Forum Moderators: phranque
I'm trying to make SEO friendly URLs with much success ... until now.
I have a 301 redirect on a specific old file then a couple of rewrites. I don't want the second rewrite to run if the first one does. I thought [L] stopped that.
Here's my .htaccess
Options -indexes FollowSymLinks ExecCGI
#Redirect old articles
redirect 301 /old-article-01.htm http://www.example.com/Article/26/
rewriteEngine on
##
## Externally redirect to add missing trailing slash if URL path does not contain a period or end with a slash
rewriteCond $1 ^[^\.]+[^/]$
rewriteRule (.*) http://%{HTTP_HOST}/$1/ [R=301,L]
## Internally rewrite SEO-friendly URLs to script
rewriteRule ^Article/([^/]+)/$ /Articles/Show.PHP?Id=$1 [L]
rewriteRule ^old-([^/]+).htm$ /Articles/Show.PHP?Service=old-$1 [L]
It works fine if I comment out the second rewrite, but I need that one as well for other redirects.
What am I doing wrong?
Thanks
Kenton
You can't guarantee which order they will be run in.
That can lead to a redirection chain, or to a redirect being actioned after a rewrite has updated the internal pointers to point to the real file location. Both are bad news.
Change your first Redirect to use RewriteRule with [R=301,L].
Use RewriteRule for all.
If you need to clear a query string as part of a redirect, append a literal question mark to the end of the target URL to do so.
Be aware that your redirects do not yet fix the common www and non-www Duplicate Content issues that afflict many sites.
RewriteEngine on
#
# Externally redirect requests for old articles
RewriteRule ^old-article-01\.htm$ http://www.example.com/Article/26/ [R=301,L]
#
# Externally redirect to add missing trailing slash if requested
# URL-path does not contain a period or end with a slash
RewriteRule ^([^.]*[^/])$ http://www.example.com/$1/ [R=301,L]
#
# Internally rewrite SEO-friendly URLs to script
RewriteRule ^Article/([^/]+)/$ /Articles/Show.PHP?Id=$1 [L]
RewriteRule ^old-([^.]+)\.htm$ /Articles/Show.PHP?Service=old-$1 [L]