homepage Welcome to WebmasterWorld Guest from 54.237.54.83
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Stuck with mod rewrite after redirect
Kenton




msg:3890897
 10:00 am on Apr 12, 2009 (gmt 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

 

g1smd




msg:3890911
 11:27 am on Apr 12, 2009 (gmt 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.

jdMorgan




msg:3890999
 3:40 pm on Apr 12, 2009 (gmt 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

Kenton




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

Thanks Guys!

Works Great.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved