Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have a .htaccess file with one simple RewriteRule:

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

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

I checked this rule with an RewriteRule tester which gave me the results I want to achieve. On my local development system 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 theres 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?

share|improve this question
1  
Does the remote server allow overrides with .htaccess? Is mod_rewrite enabled? –  ionFish Mar 30 '12 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 Apr 2 '12 at 7:08
add comment

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
    
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 Sep 21 '12 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 Sep 21 '12 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 Sep 21 '12 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 Sep 21 '12 at 17:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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