Welcome to WebmasterWorld Guest from 54.147.20.131

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Stuck with mod rewrite after redirect

     

Kenton

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

10+ Year Member



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

g1smd

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

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



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.

jdMorgan

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

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



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

Kenton

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

10+ Year Member



Thanks Guys!

Works Great.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month