简体   繁体   中英

301 Redirection from no-www to www in wordpress

I have a wordpress website in the folder: /var/www/wordpress and I have a domain called: mydomain.com .

In the hosting I did an A REGISTER with a zone WWW .

And now I need to do a 301 Redirection from http://midomain.com to http://www.midomain.com but what I'm trying doesn't work and the SEO checker doesn't validates my .htaccess

My .htaccess in /var/www/wordpress/.htaccess is like this:

<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.midomain.com$ [NC]
RewriteRule ^(.*)$ http://www.midomain.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

But doesn't work. Somewhere I red that you need to write the next lines:

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

Above # BEGIN Wordpress, but in my case doesn't work too.

Anyone knows how to do a 301 redirection from no-www to www in WordPress?

Thanks for your help and dedication.

PD: www.midomain.com doesn't exist, the real one is other.

You don't need .htacesss code. Please go to Admin panel settings and General tab... And than change WordPress Address (URL) and Site Address (URL) with www version

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM