Results 1 to 10 of 10

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

  1. #1
    Cormac Moylan Cormac's Avatar
    Join Date
    Jan 2006
    Location
    Cork
    Posts
    1,263
    Post Thanks / Like

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

    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

  2. #2
    Hardcore Geek
    Join Date
    Aug 2006
    Location
    Dublin
    Posts
    1,075
    Post Thanks / Like

    Default

    Try this one

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

  3. #3
    Cormac Moylan Cormac's Avatar
    Join Date
    Jan 2006
    Location
    Cork
    Posts
    1,263
    Post Thanks / Like

    Default

    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.

  4. #4
    Web Slave blacknight's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    10,011
    Post Thanks / Like

    Default

    So is it working now?

  5. #5
    Wannabe Geek daviddoran's Avatar
    Join Date
    Aug 2006
    Location
    Meath, Ireland
    Posts
    342
    Post Thanks / Like

    Default

    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.

  6. #6
    Hosting Caretaker niall's Avatar
    Join Date
    Jan 2007
    Location
    Carlow
    Posts
    87
    Post Thanks / Like

    Default

    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.

  7. #7
    Coder johnmryan's Avatar
    Join Date
    Mar 2007
    Location
    Dublin
    Posts
    68
    Post Thanks / Like

    Default

    Is there are reason one would do this... just wondering?

  8. #8
    Hosting Caretaker niall's Avatar
    Join Date
    Jan 2007
    Location
    Carlow
    Posts
    87
    Post Thanks / Like

    Default

    Quote Originally Posted by johnmryan View Post
    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

  9. #9
    Hosting Caretaker niall's Avatar
    Join Date
    Jan 2007
    Location
    Carlow
    Posts
    87
    Post Thanks / Like

    Default

    Looks like there is a wordpress plugin for doing this:

    No WWW « Extend › Plugins

  10. #10
    Cormac Moylan Cormac's Avatar
    Join Date
    Jan 2006
    Location
    Cork
    Posts
    1,263
    Post Thanks / Like

    Default

    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!

Visitors found this page by searching for:

wordpress htaccess no www

wordpress no .htaccess

no htaccess file wordpress

wordpress no www htaccess

no www rewrite

rewrite no www

no www htaccess wordpress

wordpress htaccess without www

http://www.irishwebmasterforum.com/blogs-and-blogging/1477-wordpress-htaccess-file-no-www-mod.html

wordpress no htaccess file

wordpress no www

wordpress htaccess mod rewrite

htaccess no www wordpresswordpress no rewriteno .htaccess wordpressno .htaccess file wordpressmod_rewrite without modenforce no www rewritewordpress htaccess with without wwwwordpress no www.wordpress .htaccess no wwwmod rewrite to another wordpress domainwordpress no htaccesswordpress htaccess www or nono www wordpress

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •