Help with Rewrite rules
9 posts
• Page 1 of 1
Help with Rewrite rules
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.
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.
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Help with Rewrite rules
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
And our FAQ will provide you with basic rules and information about mapfiles.
Regards
Andrew
Re: Help with Rewrite rules
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.
# 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.
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Help with Rewrite rules
I would do the following:
Map File should contain: 1234 part/5678.htm
Regards
Andrew
- 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
Re: Help with Rewrite rules
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.
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.
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Help with Rewrite rules
Lets find out the reason. Please, provide the rewrite.log for the testing request.
Logging issues are described in FAQ.
Regards
Andrew
Logging issues are described in FAQ.
Regards
Andrew
Re: Help with Rewrite rules
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
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
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Help with Rewrite rules
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
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
Re: Help with Rewrite rules
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
Correct syntax was ^.*products/([^/]+)/.*$
This worked in all cases with or with anything after the product slash.
Best regards,
Gary
9 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests