Try this one
HTML Code:RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www\.cormacmoylan\.com$ [NC] RewriteRule .* http://www.cormacmoylan.com/ [L,R=301]
I currently have this as my .htaccess file for WP
I want to be able to enforce no-www on the entire domain. I have addedCode:# 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 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?Code:RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^cormacmoylan.com$ [NC] RewriteRule ^(.*)$ http://cormacmoylan.com/$1 [L,R=301]
Many thanks
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.
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.
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.
Is there are reason one would do this... just wondering?
Use Of www
Also, having more than one domain pointing at your site without a 301 redirect can dilute your pagerank as I understand it.
Last edited by niall; 14-03-2007 at 04:01 PM. Reason: Spelling error
Looks like there is a wordpress plugin for doing this:
No WWW « Extend › Plugins
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!