Reputation: 325
I have a wordpress site accessed like http://example.com/
but my client wants to have it accessed like http://www.example.com/
I am finding this code as a solution
# 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
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ www.domain.com/$1 [L,R=301]
But I am getting an error of redirect loop
Could you please advice me what am i doing wrong?
Upvotes: 3
Views: 1713
Reputation: 11
You have an easy way to do this inside of wordpress:
Go to your wordpress dashboard and:
1) Select Settings 2) Select option General, 3) Add to your WordPress Address (URL) the www part 4) Add to your Site Address (URL) the www part
And done!
Upvotes: 1
Reputation: 785196
You're missing http://
from your www
forcing rule. Also important is to have your www rule before other WP rules:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Also don't forget to change WP permalinks to have www
in Site and Home URLs
Upvotes: 6