.htaccess remove www.

Setting up a multisite to use subdomains says it is better to remove the www. prefix.

I have tried adding this to my .htaccess but it gives me a redirect error message on the page.

Please can someone tell me what I have done wrong? the added lines in bold.

SetEnv DEFAULT_PHP_VERSION 53

DirectoryIndex index.cgi index.php

# 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]
RewriteCond %{HTTP_HOST} ^www.closefocus.net [NC]
RewriteRule ^(.*)$ http://closefocus.net/$1 [L,R=301]

</IfModule>

# END WordPress

  • Mason
    • DEV MAN’s Sidekick

    That looks correct. Try moving the new condition and rule above your WordPress bits like this:

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

    Or doing it completely differently via this method:

    RewriteCond %{HTTP_HOST} ^www\.(.+)
    RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
    RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]

    Again, those lines would go before the WordPress-default rules. Let us know how it goes for ya.

  • Mason
    • DEV MAN’s Sidekick

    Honestly, I've seen where the exact lines of code will work in one environment and not the next. Frustrating.

    One more try:

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

    There's no reason the code above should function any differently than the original, but ya never know.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.