How to redirect from www.domain.com to domain.com
-
If you have a WordPress blog installed in you root directory and you want all visitors who come to http://www.dmoain.com to be automatically redirected to domain.com (without the www prefix) then here is the solution. Using this solution will also keep your current directory sturucture, so if a visitor requests http://www.domain.com/dir/ he will be redirected to domain.com/dir/.
Your current .htaccess in your root web directory should look like this before you start:
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
After modification, this is how it looks:
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^domain.com$ [NC] RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
We only added the following two lines (a 301 redirect):
RewriteCond %{HTTP_HOST} !^domain.com$ [NC] RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
I hope this helps
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
- The topic ‘How to redirect from www.domain.com to domain.com’ is closed to new replies.