redirect domain name with www

ron13315

Member
Joined
Jul 23, 2014
Messages
283
Points
18
hi.. how can you manage to redirect your domain.com into www.domain.com

I manage to do it in non wordpress site by adding this code in .htaccess
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

the trouble is its not working in wordpress site. I tried different format but its not working.
all this code below is not working in wordpress site

Code:
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [R=301,L]
Code:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [R=301,L]
</IfModule>
# END WordPress
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]
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [R=301,L]
</IfModule>
# END WordPress
 

MightWeb

New member
Joined
Mar 9, 2015
Messages
182
Points
0
I actually do it quite the reverse (removing the www) - but here's how I'd do it:

Code:
RewriteEngine On
DirectorySlash Off
Options -MultiViews

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ http://www.yourdomain.tld/$1 [L,R=301]
 

wms

Administrator
Staff member
Joined
Jul 7, 2012
Messages
845
Points
63
You don't need to add codes to htacess file for redirecting from non www to www in wordpress

Worpdress has already has it if you set full domain with www in general setting in wp-admin

for example:

Don't miss www in URL above

:D
 

MightWeb

New member
Joined
Mar 9, 2015
Messages
182
Points
0
Ah, that makes sense as to why it said too many redirects as well. We force it to go www, WordPress is set up with non-www and wants to go back.
 

ron13315

Member
Joined
Jul 23, 2014
Messages
283
Points
18
Whahaha after all the trouble it was in general setting in WP dashboard.. at first I dont really think I can set it in WP setting because i saw some htaccess tutorial when I browse google.
 

ron13315

Member
Joined
Jul 23, 2014
Messages
283
Points
18
anyway there is something bugging me about this..

after removing this code in my non wordpress site to make it back to non www site.
I wonder why its still redirecting to www even I already removed the code I inserted erlier?

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
 
Older threads
Replies
1
Views
3,186
Replies
8
Views
3,551
Replies
8
Views
4,707
Newer threads
Latest threads
Replies
2
Views
394
Replies
1
Views
370
Replies
4
Views
1,891
Replies
3
Views
797

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top