+ Reply to Thread
Results 1 to 10 of 10

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

  1. #1
    Cormac's Avatar
    Cormac is offline Cormac Moylan Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of
    Join Date
    Jan 2006
    Location
    Cork
    Posts
    1,260

    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
    Gavin is offline Hardcore Geek Gavin has a spectacular aura about
    Join Date
    Aug 2006
    Location
    Dublin
    Posts
    1,074

    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's Avatar
    Cormac is offline Cormac Moylan Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of
    Join Date
    Jan 2006
    Location
    Cork
    Posts
    1,260

    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
    blacknight's Avatar
    blacknight is offline Web Slave blacknight is a splendid one to behold blacknight is a splendid one to behold blacknight is a splendid one to behold blacknight is a splendid one to behold blacknight is a splendid one to behold blacknight is a splendid one to behold blacknight is a splendid one to behold blacknight is a splendid one to behold
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    7,903

  5. #5
    daviddoran's Avatar
    daviddoran is offline Wannabe Geek daviddoran will become famous soon enough
    Join Date
    Aug 2006
    Location
    Meath, Ireland
    Posts
    342

    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
    niall's Avatar
    niall is offline Hosting Caretaker niall will become famous soon enough
    Join Date
    Jan 2007
    Location
    Carlow
    Posts
    85

    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
    johnmryan's Avatar
    johnmryan is offline Coder johnmryan will become famous soon enough
    Join Date
    Mar 2007
    Location
    Dublin
    Posts
    66

    Default

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

  8. #8
    niall's Avatar
    niall is offline Hosting Caretaker niall will become famous soon enough
    Join Date
    Jan 2007
    Location
    Carlow
    Posts
    85

    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 05:01 PM. Reason: Spelling error

  9. #9
    niall's Avatar
    niall is offline Hosting Caretaker niall will become famous soon enough
    Join Date
    Jan 2007
    Location
    Carlow
    Posts
    85

    Default

    Looks like there is a wordpress plugin for doing this:

    No WWW « Extend › Plugins

  10. #10
    Cormac's Avatar
    Cormac is offline Cormac Moylan Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of Cormac has much to be proud of
    Join Date
    Jan 2006
    Location
    Cork
    Posts
    1,260

    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!

+ Reply to Thread

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

Search Engine Optimization by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64