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.
Answer
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
Related Questions
- → CORS missmatch because of http
- → Building sitemap for 2 wordpress install under 1 domain
- → How to remove empty elements after class?(jQuery)
- → Get width of an element and apply to another relative to the first one?
- → How to remove caption p class from wordpress?
- → 301 Redirection from no-www to www in wordpress
- → Laravel 5 routing using prefix
- → WordPress - Header position Top, Left &Right
- → how to add rel=nofollow to some specific external links in wordpress
- → octobercms install error: database is not empty?
- → How to edit the index page of wordpress theme?
- → How to select a Post Type (Wordpress) to pass a filter in head?
- → What sort of URL structure should be used to display AMP HTML vs vanilla HTML