Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 

Apache rewrite rules are very powerful to rewrite URLs of a website by using the .htccess file. Unfortunately there is no way to debug these rulesif you don't have any access to the Apache installation. That's a common issue of users of managed servers. YOu have to execute a trial and error cycle in order to get your rules right. If you follow some rules you will be successfull to create your rules and don't affect any visitors of your website.

 

First of all you have to be familiar with regular expressions to create the rules and to iterate them with tests. See links below.

1) Use 302 to test your rules

301 are cached by browsers which creates serious problems for your visitors and for you when you're testing your rules. In addition don't change to 301 when you think your rules are OK. Just wait for some period of time until switching to 302. Otherwise visitors of your wbesite will get 404 even you fixed an incorrect rule in the meantime.

2) Use a special user agent for your tests

That way it's only you who will be redirected but no other website visitor will be affected by your tests.

RewriteCond %{HTTP_USER_AGENT}  ^my-test-user-agent$
RewriteCond %{HTTP_HOST} ^www\.myWebsite\.de$ [NC]
RewriteRule ^ http://www.google.de [L,R=302]

3) Use wget in order to bypass any caching and use the special test user agent

wget -U "my-test-user-agent" http://www.myWebsitede

 

Useful links

http://stackoverflow.com/questions/9153262/tips-for-debugging-htaccess-rewrite

Online Regex Tester

Ein weiterer Online Regex Tester

Noch ein Online Regex Tester

rewrite online Tester

Apache URL rewriting guide

Regular expression info

Regex Tutorial

Add comment

*** Note ***

Comments are welcome. But in order to reject spam posts please consider following rules:
  1. Comments with string http are rejected with message You have no rights to use this tag
  2. All comments are reviewed by hand and thus it usually takes one day until a comment will be published.