How to redirect url using .htaccess for WordPress websites?

If your website is not set up with WordPress, things would be easier for you to redirect one url to another using .htaccess.

This will redirect to But WordPress uses .htaccess for its own redirection. Simply adding a rewrite rule like above does not work.

You will find you still get the content of¬† in your browser instead of test2.php. The reason is that after test1.php is redirected to test2.php, it is further redirected to index.php. Index.php gets the content of a post based on $_SERVER['REQUEST_URI'] while $_SERVER['REQUEST_URI'] keeps “/test1.php”(not “/test2.php”). Changing



does not work because in both cases only one http request is issued and $_SERVER['REQUEST_URI'] keeps the same. You should change the rewrite rule to:

Now, the first http request is replied with a 301 response with the redirected url. Then the browser issues the second http request with the new url and $_SERVER['REQUEST_URI'] changes to “/test2.php”.

Reference: [1],[2],[3]


Posted in tips of hosting