Web Development

Apache 301 Homepage redirects with .htaccess and mod_rewrite

There are hundreds of sources explaining this, but whenever you need one, you can't find a matching one , so I'll repost my sample…

The goal: redirect NON-www addresses the corresponding WWW-address to make sure search engines and users always use the correct one and don't put you under some SE penalties.

E.g. professional-pm.com should redirect to www.professional-pm.com

This instructions applies to Apache, using mod_rewrite commands

  • Step 1 : create a simple file called ".htaccess"
  • Step 2 : fill the following in you file

Quote:

Options +FollowSymlinks All -Indexes

rewriteEngine on

rewriteBase /

RewriteCond %{HTTP_HOST} ^professional-pm.com$

RewriteRule ^(.*)$ http://www.professional-pm.com [R=301,L]

Of course replace "professional-pm.com" with your domain name.

  • Step 3 : AFTER CHECKING if there are no other .htaccess files there ( then you should add the RewriteCond part only to those) upload that file into your web server's root (e.g. public_html ) and you should be done, unless your web host has disabled mod_rewrite for some reason…
Average rating
(0 votes)

Similar entries