Help with Rewrite rules

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 5
Joined: 06 Apr 2012, 23:26

Help with Rewrite rules

06 Apr 2012, 23:36

I have a site with over 3000 pages where we are changing the folder name and file name. Here is an example:
products/xyz/index.htm (old) to /product/xyz.htm (new). I am planning on using a map file to create a 301 redirect.

I also have another problem I would like to correct at the same time. Google started listing many pages (not just the "products" folder ones) from our site as HTTPS:// instead of HTTP://.

How do I code the rewrite rules to solve both of these problems? Thanks in advance for your assistance.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Help with Rewrite rules

09 Apr 2012, 06:31

In our examples section you'll find a general rule to direct all https traffic to http.

And our FAQ will provide you with basic rules and information about mapfiles.

Regards
Andrew

User avatar
Posts: 5
Joined: 06 Apr 2012, 23:26

Re: Help with Rewrite rules

10 Apr 2012, 13:36

Thank you. I have attempted to write the rules but i am not getting the results I need. Here is what is in the .htaccess file:
# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.89

RewriteEngine on
RewriteBase /
RewriteMap mapfile txt:F:/Inetpub/skumap.txt [NC]
RewriteRule ^products/([^/]+)\* /manufacturer/${mapfile:$1} [NC,R=301,L]

RewriteCond %{HTTPS}=on [AND]
RewriteCond %{THE_REQUEST} !^.*/shopcart\/([^/]+)\/([^/]+)\.cgi\ HTTP/
RewriteRule ^(.*)$ http://www.xyz.com/$1 [R=301,L]

Requests come in for: product/1234/ (often with nothing after the slash, somes with index.htm)
Map File contains line: 1234/ part/5678.htm
Should render as: manufacturer/part/5678.htm

For HTTPS redirect I need to exclude shopping cart.

Any assistance or pointers is appreciated.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Help with Rewrite rules

11 Apr 2012, 06:03

I would do the following:

Code: Select all
RewriteEngine on
RewriteBase /
RewriteMap mapfile txt:F:/Inetpub/skumap.txt [NC]
RewriteRule ^products/([^/]+)/?$ /manufacturer/${mapfile:$1} [NC,R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^.*/shopcart\/([^/]+)\/([^/]+)\.cgi\ HTTP/
RewriteRule ^(.*)$ http://www.xyz.com/$1 [R=301,L]


Map File should contain: 1234 part/5678.htm

Regards
Andrew

User avatar
Posts: 5
Joined: 06 Apr 2012, 23:26

Re: Help with Rewrite rules

18 Apr 2012, 23:17

This seems to work when I copy it into the htaccess file for the site and I try the RegExp Test which passes. After I hit the apply button then go back to the RegExp test it gives an error "Bad RewriteRule format". I tried it with only the map file redirect portion and same error. This is what is currently in the htaccess file:
RewriteEngine on
RewriteBase /
RewriteMap mapfile txt:F:/Inetpub/skumap.txt [NC]
RewriteRule ^products/([^/]+)/?$ /manufacturer/${mapfile:$1} [NC,R=301,L]

request coming in like: www.xyz.com/products/1234/ or
www.xyz.com/products/1234/index.htm
should redirect to www.xyz.com/manufacturer/part/5678.htm

Best regards.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Help with Rewrite rules

19 Apr 2012, 06:34

Lets find out the reason. Please, provide the rewrite.log for the testing request.
Logging issues are described in FAQ.

Regards
Andrew

User avatar
Posts: 5
Joined: 06 Apr 2012, 23:26

Re: Help with Rewrite rules

19 Apr 2012, 13:25

Attached is a copy of the rewrite log. This was on the live server and not using the RegExp test but an actual URL request. The error log copy is at the bottom of the file. I noticed that the log shows other items but these items have full URL paths.

As a side note, the HTTPS to HTTP redirect is working fine with the code supplied when I include it in the htaccess file.

Best regards
Attachments
RewriteLog4.19.2012.zip
(1.75 KiB) Downloaded 1586 times

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Help with Rewrite rules

20 Apr 2012, 07:00

Very strange. It should have matched the pattern.
Just to make sure it's not regular expression I'd suggest trying "products/(.+)" instead of "products/([^/]+)/?"

Such a strange behaviour could be a result of double registration. I didn't ask if it's IIS6 or not, but, please, follow this article

Regards
Andrew

User avatar
Posts: 5
Joined: 06 Apr 2012, 23:26

Re: Help with Rewrite rules

21 Apr 2012, 00:16

It is IIS6. It was a double registration issue from an old test installation of Rewrite.
Correct syntax was ^.*products/([^/]+)/.*$
This worked in all cases with or with anything after the product slash.
Best regards,
Gary

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 0 guests