Mobile app version of vmapp.org
Login or Join
Steve110

: Help with Apache mod_rewrite rules I want to change some legacy URL's like this: /modules.php?name=News&file=article&sid=600 to this: /news/story/600/ This is what I have tried: RewriteEngine

@Steve110

Posted in: #Apache #ModRewrite

I want to change some legacy URL's like this:

/modules.php?name=News&file=article&sid=600


to this:

/news/story/600/


This is what I have tried:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^name=News&file=([a-z_]+)&sid=([0-9]+)
RewriteRule ^modules.php /news/story/%2/ [R=301,L]


However I still get 404's on the old URLs.

I do have some other rewrite rules working, so I am pretty sure mod_rewrite is enabled and functioning. These rules are in a httpd.conf file in a VirtualHost container.

I should also mention this is for a Python application (using Django) running with mod_wsgi. Should the rewrites happen before the URLs are passed to the wsgi application?

Any ideas? Thanks.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Steve110

1 Comments

Sorted by latest first Latest Oldest Best

 

@Merenda212

I got it to work. It seems I had a couple of problems.


I needed a forward slash on the pattern in RewriteRule; i.e.
^/modules.php instead of
^modules.php.
I needed to prevent the query string from being appended to the new URL. This could cause recursion in some cases, or other strange things (400 bad request). A trailing ? did the trick.


I ended up with this:

RewriteEngine on
RewriteCond %{QUERY_STRING} sid=([0-9]+)
RewriteRule ^/modules.php /news/story/%1/? [R=301,L]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme