I have a .htaccess file with one simple RewriteRule:

RewriteEngine on
RewriteRule ^([A-Za-z0-9-]+)$ ?site=$1

I want to have a URL like http://www.example.com/imprint and forward it to http://www.example.com/?site=imprint.

I checked this rule with a RewriteRule tester which gave me the results I want to achieve. On my local development server it works well too.

But on a remote server the URLs just give me a 404 error. Other more simple rewrite rules are working with no problems, so everything must be set up correctly (I think..). The problem is that I don't have access to any error logs or the server configs. So the only thing I can do is to guess...

Can anyone tell me if there's something wrong with this rule? Or anything else I can do or test to solve this? Or has someone an idea what could be wrong on the server?

  • 1
    Does the remote server allow overrides with .htaccess? Is mod_rewrite enabled?
    – ionFish
    Commented Mar 30, 2012 at 15:28
  • It must be. I can't check it in the configs but like I said, if I use another more simple rule e.g. redirect every pagecall to www.google.com it works.
    – m0tv
    Commented Apr 2, 2012 at 7:08

1 Answer 1


Try slash before the ?, like

RewriteEngine on
RewriteRule ^([A-Za-z0-9-]+)$ /?site=$1

If that doesnt work, try adding [R] after $1 so it will actually rewrite the url and you can see where it goes in your browser url bar

  • Thank you very much. The slash works like a charm. Without the slash and adding the [R] I get redirected to the whole filesystem path like www.example.com/www/hosting/XXX/XXX/websites/example/?site=imprint Can you explain this behaviour to me? Why does it work on other servers but not on this one? Is there some configuration for that?
    – m0tv
    Commented Sep 21, 2012 at 8:58
  • what are the 2 server environments? As in like WAMP vs Linux? Apache versions the same? Maybe one has RewriteBase / in .htaccess and the other doesn't? Or maybe one of the DocumentRoot in httpd.conf (or vhosts) contains a trailing slash at the very end of the folder path where as the other doesn't? Honestly I learned starting out redirect urls should always start with / if not full http:// path, so I can't really speak to the expected behavior of non / urls like you originally had because I never use them...
    – WebChemist
    Commented Sep 21, 2012 at 9:29
  • Hm ok, many things can be the cause for this behaviour. I just try to accustom myself to always write the redirect URLs with a trailing slash.
    – m0tv
    Commented Sep 21, 2012 at 9:50
  • I found this tutorial (especially part 2) particularly helpful when I first started playing around with htaccess, hopefully you or anyone reading this finds it helpful as well: corz.org/serv/tricks/htaccess.php
    – WebChemist
    Commented Sep 21, 2012 at 17:49

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.