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


to this:


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.

2 Answers 2


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

  1. I needed a forward slash on the pattern in RewriteRule; i.e.
    ^/modules.php instead of ^modules.php.

  2. 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]

Where are these "other rewrite rules" located? In the same .conf or .htaccess file? I think you need Options +FollowSymlinks on the line just above RewriteEngine on.

  • The working rewrite rules are right next to the ones that don't work, in a .conf file. They are in a VirtualHost container.
    – Brian Neal
    Commented Feb 27, 2011 at 2:58
  • Did you try what I mentioned about Options +FollowSymlinks? You could try putting the rewrite-rules in a .htaccess file.
    – user5688
    Commented Feb 27, 2011 at 3:09
  • I did try the Options + FollowSymlinks, but it didn't work.
    – Brian Neal
    Commented Feb 27, 2011 at 3:21
  • I'm not using a .htaccess file; this is for a Python / WSGI application where the URL's don't really map to a directory (at least that is my understanding). But I don't know what I'm doing for sure. :)
    – Brian Neal
    Commented Feb 27, 2011 at 3:24
  • FollowSymLinks is not actually required when mod_rewrite is used directly in the server config / VirtualHost.
    – MrWhite
    Commented Jan 23, 2017 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.