.htaccess query

Status
Not open for further replies.

Cormac

New Member
Hi guys, i wish to add to the current .htaccess file that resides in my blog root so that if a user types in http://domain.com they're automatically redirected to http://www.domain.com.


I have opened up the current .htaccess file and I found the following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress


To enforce the www i added the following to the .htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_Host} ^cormacmoylan.com/blog [NC]
RewriteRule ^(.*)$ http://www.cormacmoylan.com/blog/$1 [L,R=301]


But it doesn't enforce the rule. Does anyone know where i'm going wrong?
 

Gavin

New Member
I dont think you need it in the blog but rather in the root folder of the domain although I find htaccess tricky at the best of times.

Try:

RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$ [NC]
RewriteRule .* http://www.yourdomain.com/ [L,R=301]
 

RedCardinal

New Member
Where did you put the second block?

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks
RewriteCond %{HTTP_Host} ^cormacmoylan.com/blog [NC]
RewriteRule ^(.*)$ http://www.cormacmoylan.com/blog/$1 [L,R=301]
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress

Similar works for me except it appears WP takes it upon itself to rollback the file every so often :(
 

Redfly

New Member
RewriteEngine On

RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Then in your case, /blog
 
Status
Not open for further replies.
Top