Welcome to WebmasterWorld Guest from 54.162.151.77

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

301 redirect and mod_rewrite

     
11:47 pm on Sep 1, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 18, 2003
posts:1929
votes: 0


I have a section of a website that uses mod_rewrite to generate articles from database. Folder "/articles/" has only one file - ".htaccess". That file contains rules and it rewrites any request to "/articles/article_path/" to perl script that finds article in the database with entry "article_path" and displays it.

I changed path of one of the article and it was spidered by Zealbot, so I made a 301 redirect to the new path. ".htaccess" file with redirect is in the root of the server.

Now, Apache, redirects to a new path, plus adding query string that it rewrites to Perl script.

This is very confusing, but here is an example.

Old path:

/articles/bluewidget/

New path:
/articles/very_blue_widgets/

Rewrite rule in
/articles/
folder:
RewriteRule ^([a-zA-Z0-9_-]*)/?$ /cgi-bin/art.pl?path=$1&display=1

301 redirect (in root):
redirect 301 /articles/bluewidget/ http://www.widgets.com/articles/very_blue_widgets/ 

Apache rewrites to:
http://www.widgets.com/articles/very_blue_widgets/?path=very_blue_widgets&display=1

How can I prevent this kind of rewrite?

12:34 am on Sept 2, 2003 (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


Moltar,

This must be some weird interaction between mod_alias and mod_rewrite. I've looked at it for several minutes, and I can't figure out why it does not rewrite to the art.pl path.

Try doing the whole thing in mod_rewrite in your /articles subdirectory:


RewriteRule ^bluewidget/$ http://www.widgets.com/articles/very_blue_widgets/ [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]*)/?$ /cgi-bin/art.pl?path=$1&display=1 [L]

Jim

12:55 am on Sept 2, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 18, 2003
posts:1929
votes: 0


Thank you Jim, this worked fine :)