大家早上好! 我试图在通过AWS托管的Wordpress网站中使用htaccess重定向http-> https和www。 ->非www。,例如:http://www.example.com至https://example.com。
当前,http到https重定向正在按预期工作。但是,“ www。”没有从我的网址中删除,即http://www.example.com变成https://www.example.com
注意:对于其他重定向,我使用重定向插件。此外,我将Really Simple SSL插件用于https。
我尝试了重定向代码的多种变体,清除缓存,使用隐身模式进行检查等。
这是我正在使用的当前代码:
# 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
任何建议将不胜感激!谢谢!
答案 0 :(得分:1)
您可以尝试这种方式:
###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指示,您应该没有任何问题,