Permanent 301 Redirect the easy way

First, .htaccess and mod_rewrite can be very tricky and if you break your website redirect you may even fix it and not know because your browser session has not been restarted.

Use [R] instead of [R=301] while you are testing . When you are 100% certain the rule does exactly as it’s expected to, then switch it to [R=301] for your live site.

How to redirect any and all website pages to another website removing the page reference. This way if you have an old website with old links everyone will be redirected to the front door. Search engines will see the permanent 301 redirect and update their index to not list your old website.

# redirect anything with base url in the second line to the first one and remove any page references
redirectMatch 301 ^(.*)$
redirectMatch permanent ^(.*)$

Redirect with URL masking:
“the apache rewriteengine doesn’t have any functionalities to mask URLs. Traditional masking techniques (pull out the source of the page that’s been masked and you’ll see) is done through a frame.

However you can accomplish dynamic masking by a little bit of additional code (I have an example in django but it’s out of the scope of this discussion.)

Here’s a basic masking frame

<frameset rows = “100%, *” border = “0” framespacing=”0″ frameborder=”0″>

<frame noresize = “” src = “”></frame>



That would be for contemporary redirects.

Let’s say that you want to redirect to

The usual .htaccess redirect rule would be

RewriteEngine on
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^.*$ “” [R=301,L]

in apache.

(The string of ” acts as escape sequences for [‘:’,’/’,’.’], with a R response code of 301)

However this does not allow you to mask the pages.

In order to achieve masking effects, use the following as your HTML in the index.html file on

<frameset rows = “100%, *” border = “0” framespacing=”0″ frameborder=”0″>

<frame noresize = “” src = “”></frame>


Just copy paste this into the index.html file under and it should work.”

More .htaccess tricks with various redirects and how to do them:


Leave a comment