简体   繁体   English

301在Wordpress中从无www重定向到www

[英]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 . 我在/ var / www / wordpress文件夹中有一个wordpress网站,并且我的域名为: mydomain.com

In the hosting I did an A REGISTER with a zone WWW . 在主持人中,我对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 现在,我需要从http://midomain.comhttp://www.midomain.com进行301重定向,但是我尝试的操作不起作用,并且SEO检查器无法验证我的.htaccess

My .htaccess in /var/www/wordpress/.htaccess is like this: 我在/var/www/wordpress/.htaccess中的 .htaccess是这样的:

<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. 在#BEGIN以上的Wordpress上,但在我来说也不起作用。

Anyone knows how to do a 301 redirection from no-www to www in WordPress? 有谁知道如何在WordPress中从no-www到www进行301重定向?

Thanks for your help and dedication. 感谢您的帮助和奉献。

PD: www.midomain.com doesn't exist, the real one is other. PD:www.midomain.com不存在,真正的一个是另一个。

You don't need .htacesss code. 您不需要.htacesss代码。 Please go to Admin panel settings and General tab... And than change WordPress Address (URL) and Site Address (URL) with www version 请转到管理面板设置和“常规”选项卡...然后使用www版本更改WordPress地址(URL)和站点地址(URL)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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