1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress htaccess & permalinks.

Discussion in 'General Scripting Chat' started by Allie Albatross, Jul 26, 2011.

  1. Allie Albatross

    Allie Albatross Junior Member

    Joined:
    Jan 31, 2009
    Messages:
    116
    Likes Received:
    44
    Location:
    Austin, TX
    I'm somewhat confused. When you enable permalinks, this is automatically generated by Wordpress.

    Code:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    
    That's fine and dandy, but how do I add the section where it redirects all www to the non-www version?

    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www.domaincom [NC]
    RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
    
    Does it go between the IfModule? After? What does this even mean? D;
     
  2. GreyWolf

    GreyWolf Executive VIP Jr. VIP

    Joined:
    Aug 17, 2009
    Messages:
    1,930
    Likes Received:
    5,388
    Gender:
    Male
    Occupation:
    Artist / Craftsman
    Location:
    sitting at my PC
    You only need 'RewriteEngine On' once or you'll run into problems, so you need to combine the two sections of code into just one.
    Code:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www.domaincom [NC]
    RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress