htaccess file Help

MixerDJ

Regular Member
Joined
Nov 20, 2012
Messages
392
Reaction score
171
Hi Guys,

i need to redirect my non www version to www version. but in my htaccess file is having this code already


# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>



# END WordPress

I tried to add this code to redirect to www version but it says you are having redirect loop and site is not loading

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]

I need to know where to add this code?

should i need to keep both codes or can someone correct my codes? :eek:

Thank you guys !!:)
 
From WordPress 2.4+ (maybe) theres a feature called "canonical URLs" which will 301 redirect www to non-www or vice-versa automatically for you. You don't need to change the htaccess file.

Wordpress is taking care of this, so keep the original wp htaccess file:

Code:
# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>



# END WordPress

And just change the WordPress address (URL) and Site address (URL) from ADMIN > Settings > General to start with www.

For example http://mydomain.com becomes http://www.mydomain.com

Just to note that when making such changes on indexed site you may want to take care of some additional details one of which is telling WMT which version to prefer when crawling to avoid duplicate content.

Hope that helps.
 
Last edited:
From WordPress 2.4+ (maybe) theres a feature called "canonical URLs" which will 301 redirect www to non-www or vice-versa automatically for you. You don't need to change the htaccess file.

Wordpress is taking care of this, so keep the original wp htaccess file:

Code:
# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>



# END WordPress

And just change the WordPress address (URL) and Site address (URL) from ADMIN > Settings > General to start with www.

For example http://mydomain.com becomes http://www.mydomain.com

Just to note that when making such changes on indexed site you may want to take care of some additional details one of which is telling WMT which version to prefer when crawling to avoid duplicate content.

Hope that helps.

Thank you buddy it worked :D
 
You need to change WordPress address & Site address.

This is found in admin, then settings and change the default url to start with www.
 
Back
Top