Welcome to WebmasterWorld Guest from 54.167.86.211

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Stuck with mod rewrite after redirect

     
10:00 am on Apr 12, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 18, 2003
posts: 77
votes: 0


Hi

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]

unfortunately this is showing as
http://www.example.com/Article/26/?Service=old-article-01
instead of
http://www.example.com/Article/26/

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

11:27 am on Apr 12, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Never mix Redirect and RewriteRule in the same .htaccess file.

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.

3:40 pm on Apr 12, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


I'd suggest something like:

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]

Jim
9:30 pm on Apr 12, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 18, 2003
posts: 77
votes: 0


Thanks Guys!

Works Great.