wordpress - htaccess www -> 非 www 重定向
问题描述
大家,早安!我正在尝试在通过 AWS 托管的 Wordpress 站点中使用 htaccess 来重定向 http -> https 和 www。-> 非 www.,例如:http://www.example.com到https://example.com。
目前,http 到 https 重定向正在按预期工作。然而,“万维网”。没有从我的网址中删除,即http://www.example.com变为https://www.example.com
注意:对于其他重定向,我使用重定向插件。此外,我为 https 使用了真正简单的 SSL 插件。
我已经尝试了重定向代码的多种变体,清除我的缓存,以隐身方式检查它等。
这是我正在使用的当前代码:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
任何建议将不胜感激!谢谢!
解决方案
你可以这样尝试:
###START MOD_REWRITE
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#REDIRECT ALL www REQUESTS OF YOUR SITE TO THE non-www VERSION AND http -> https
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteCond %{HTTP_HOST} !(\.dev|staging)
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
</IfModule>
###END MOD_REWRITE
###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]
</IfModule>
###END WORDPRESS
保留默认的 WordPress 说明,您应该没有任何问题,请告诉我
推荐阅读
- python - 对列表中的所有项目运行函数(将日期列表转换为 Unix 时间戳)
- vba - 使用 VBA 在 Powerpoint 中的一张幻灯片上静音和取消静音多个音频媒体
- java - 方阵乘法与传统方式
- c# - 如何不将英文字母传递给Json
- reactjs - 展开后将图形(树)拟合到屏幕上
- amazon-web-services - 是否可以在向组织添加新账户时自动启用 AWS Config?
- laravel - Laravel 和 Vue.js | v-模型和属性问题
- windows-community-toolkit - Windows Community Toolkit 7.0.0 的 IProvider.LoginAsync 的替代品是什么
- android - 我可以在 Firestore 中设置自定义 ID 吗?
- javascript - 当使用javascript发生onclick功能时如何隐藏和显示?