简体   繁体   English

通过 .htaccess 文件将 Wordpress 站点的“www”重定向到“http://”

[英]Redirection "www" to "http://" of a Wordpress site by .htaccess file

I'm having a problem displaying my Wordpress site with the "www."我在显示带有“www”的 Wordpress 网站时遇到问题。 prefix.字首。

Indeed, when I access it via http://" the homepage is displayed normally, and when I add the prefix "www." it seems that the redirection fails and displays the contents of the directory at the root of the site :事实上,当我通过 http://" 访问它时,主页正常显示,当我添加前缀 "www." 时,似乎重定向失败并在站点的根目录显示目录的内容:

主页 www

So I wanted to modify the default .htaccess of my Wordpress website :所以我想修改我的 Wordpress 网站的默认 .htaccess :

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

By adding this redirect rule :通过添加此重定向规则:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.herefor.digital
RewriteRule (.*) http://herefor.digital/$1 [R=301,L]

But I don't know where to add the "www."但我不知道在哪里添加“www”。 to "http://".到“http://”。 This crashes the site.这会使网站崩溃。

Yes should I according to add it, and is the procedure/syntax good on its own?是的,我应该根据添加它,并且程序/语法本身是否良好?

My website link : http://herefor.digital我的网站链接: http ://herefor.digital

Thanks a lot非常感谢

Regarding the crash of your site when you implement the redirect.关于您实施重定向时网站的崩溃。 Within the WordPress Admin navigate to Settings -> General.在 WordPress 管理员中导航到设置 -> 常规。 From there make sure the "WordPress Address (URL)" and "Site Address (URL)" is set to use https://www.从那里确保“WordPress 地址 (URL)”和“站点地址 (URL)”设置为使用 https://www。 and click Save Changes at the bottom.并单击底部的保存更改。

Ok @CBroe found the source of the problem.好的@CBroe 找到了问题的根源。 My "www" host was pointing to "./" instead of the "./www" directory.我的“www”主机指向“./”而不是“./www”目录。 So I updated this via my host interface and after a few minutes, it now works!所以我通过我的主机界面更新了这个,几分钟后,它现在可以工作了!

Thanks a lot ;)非常感谢 ;)

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

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