RewriteRule working on local server but not on remote server

RewriteRule working on local server but not on remote server - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, mod-rewrite, , , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


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?


Solution :

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


Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect