Wordpress .htaccess file for no-www and mod-rewrite()

Status
Not open for further replies.

Cormac

New Member
I currently have this as my .htaccess file for WP
Code:
# 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
I want to be able to enforce no-www on the entire domain. I have added
Code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^cormacmoylan.com$ [NC]
RewriteRule ^(.*)$ http://cormacmoylan.com/$1 [L,R=301]
to a .htaccess file within the root of my site but it doesn't enforce no-www within the blog folder. How should I edit the .htaccess file within my blog folder to enforce no-www?

Many thanks
 

Gavin

New Member
Try this one

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

Cormac

New Member
Thanks gavin, but the issue I was encountering was combining the code from the modrewrite() code with the no-www code. It was getting all screwy on me.
 

daviddoran

New Member
I think you need the no-www code in httpd.conf because once the server gets to your .htaccess it has already chosen what domain/subdomain to use.
Httpd.conf lets Apache know ahead of time so it can redirect the domain request, not just at the folder/file level. AFAIK.
 

niall

New Member
Cormac,
I have that setup on my blog now, and have no major issues. The .htaccess in my wordpress folder is now as follows:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^blog.moybella.net$ [NC]
RewriteRule ^(.*)$ http://blog.moybella.net/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

In my vhost entry, blog.moybella.net is the ServerName and the ServerAlias is "www.blog.moybella.net blog.moybella.com www.blog.moybella.com"

Niall.
 

Cormac

New Member
sweet, i never had a chance to check the code you supplied but i came across a wordpress blog that i setup which forces no-www and also uses mod rewrite...the answer is never too far away!
 
Status
Not open for further replies.
Top