How to create a 301 redirect?

As described on URL Canonicalization article we published in March, having a unique URL ("canonicalization") for each webpage is important in improving your "Pagerank". Canonicalization is accomplished by redirecting non-standard webpages to a preferred ("standard") webpage. There are a number of ways to redirect a webpage, but 301 (HTTP/1.1 Status Code, "Moved Permanently") redirect is the search engine friendly method which passes the pagerank and search engine ranking status from old to a new page. Here is an examples of how 301 redirect can be implemented on LAMP (Linux/Apache/Mysql/PHP) environment.

PHP Redirect

Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location:" );

Apache .htaccess: non-www to www subdomain redirect

1. Make sure your httpd.conf file has the "Directory" directive with the "AllowOverride All" setting.

<Directory /path/to/your/domain/document/root>
    AllowOverride All

2. Enable Mod-Rewirte Module

Your apache configuration should have the mod-rewrite module enabled, which is the default. You can verify this by perusing httpd.conf file for the following line:

LoadModule rewrite_module modules/

3. Create a .htaccess file in the document root directory of your website with the following content.

RewriteEngine On
RewriteCond %{http_host} ^ [nc]
RewriteRule ^(.*)$$1 [r=301,nc]

Just replace the "" with the domain name you're trying to redirect.



You may redirect a user to new page via Meta Refresh.

By having content=0 (0 second wait before redirect) causes 30x (301 or 301 redirect) depending on the search engine.

The Meta redirect will only work on browsers where it is supported. Visitors can disable the meta refresh feature in their browser for security reasons.

By aladar

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.