Redirecting a website using .htaccess

A few weeks ago, I started working for a new institution. I needed to move my website from the old institution's web server to the new one, that is from to

For simple cases, you can get away with Redirect 301.

If you need something a little more sophisticated, you can use Apache's URL rewriting engine, which can do some fancy stuff. This link was also useful.

In my case, I ended up adding the following three lines in the .htaccess file (the file should be located in the directory of the site that needs redirection; if there is none, just create one with a text editor. Remember that files starting with . will automatically be hidden).

RewriteEngine on
RewriteRule .*Photography/(.*)$1 [R=301,L]
RewriteRule .* [R=301,L]

The second line redirects all pages of the Photography directory into the same page of the photography directory of the new institution. The third line redirects any page of the directory where the .htaccess is saved to the Welcome.html page at the new institution. R=301 means that it is a permanent change and L is there to say that the URL will not be rewritten by future RewriteRule if the URL matches the rule.


Popular Posts