I have a wordpress website


on the wwww version www.mywebsite.net wordpress doesn't load

so want that if the user open the www version of my website is redirect to the non-wwww version

here my .htaccess

# Do not remove this line or mod_rewrite rules and search engine friendly URLs will stop working
RewriteBase /

# 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]

# END WordPress

# Enable cross-domain CORS

<FilesMatch "\.(ttf|otf|woff)$">
<IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"

# WordPress SEO - XML Sitemap Rewrite Fix
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap_index.xml$ /index.php?sitemap=1 [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 [L]
  • Ideally, you should only have 1 RewriteEngine On and 1 RewriteBase directive at the top of your .htaccess file.
    – MrWhite
    Commented Jul 31, 2015 at 20:08
  • thx @AndreaF for " Header set Access-Control-Allow-Origin "*" "
    – Bruno
    Commented Oct 27, 2018 at 17:26

1 Answer 1


You can redirect your site from www to non-www version by 2 diff. ways :

First Method is

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

You can use above code in you Htaccess. But it will be something like hardcoded code as you have to specify domain name. It will work fine.

Second Method is :

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Put above code in your Htaccess file.It is dynamic code. Here no need to specify domain name.

  • Seems totally ignored :(
    – AndreaF
    Commented Jul 16, 2015 at 6:39
  • Is it not working? Commented Jul 16, 2015 at 7:01
  • Exactly. I have tried but doesn't change.
    – AndreaF
    Commented Jul 16, 2015 at 12:28
  • For me same method is working.. Commented Jul 17, 2015 at 2:45
  • @AndreaF The above directives need to go at the top your .htaccess file, before the WordPress rewrites.
    – MrWhite
    Commented Jul 31, 2015 at 19:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.