HOWTO: Redirect all non-www pages to their www counterparts using mod_rewrite
Prerequisites
Remember to backup any files first before modifying them, and if possible test changes on a non-production server first
Step 1: Create .htaccess file
If it doesn't already exist, create a file on your server's document root (the top most web accessible directory) and name it .htaccess.
Note to windows users: Windows makes it difficult to save files begging with a period, to bypass this issue name the .htaccess file something else while editing locally, and rename on the server.
Step 2: Add rewrite code to .htaccess file
Add the following lines to the the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com [NC]
RewriteRule ^(.*) http://www.mywebsite.com/$1 [L,R=301]
</IfModule>
Replace www\.mywebsite\.com with your own website, remembering to escape any periods with a backslash. Then, also replace http://www.mywebsite.com/ with your own site's address. That's it.
Comments
wordpress and rewrite
wordpress can't rewrite page ids...
this is what i been looking for!!!
wow man thanks for this, i have been looking high and low for some code to help me do the redirection... this works just right!!!
- By webtrendz website design studios at Aug 25, 2006, 11:50 am
- Reply
images with a non www.address are not more visible
after the adition some images with the non www. address are not more visible.
how to solve this problem
images with a non www.address are not more visible
after the adition some images with the non www. address are not more visible.
how to solve this problem
Submit Comment
More URL Rewriting Articles
None found
