简体   繁体   English

htaccess www->非www重定向

[英]htaccess www -> non-www redirect

Good morning, everyone! 大家,早安! I am trying to use htaccess in my Wordpress site hosted through AWS to redirect http -> https, and www. 我试图在通过AWS托管的Wordpress网站中使用htaccess重定向http-> https和www。 -> non-www., like so: http://www.example.com to https://example.com . ->非www。,例如: http : //www.example.comhttps://example.com

Currently, the http to https redirect is working as intended. 目前,http到https重定向已按预期工作。 However, "www." 但是,“ www。” is not being stripped from my urls, ie http://www.example.com becomes https://www.example.com 没有从我的网址中删除,即http://www.example.com变成https://www.example.com

Note: I for other redirects, I use the Redirection plugin. 注意:对于其他重定向,我使用重定向插件。 Furthermore I use Really Simple SSL plugin for https. 此外,我将Really Simple SSL插件用于https。

I have tried multiple variations of the redirect code, clearing my cache, checking it with incognito, etc. 我尝试了重定向代码的多种变体,清除缓存,使用隐身模式进行检查等。

Here is the current code I am using: 这是我正在使用的当前代码:

  # 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

Any advice would be greatly appreciated! 任何建议将不胜感激! Thank you! 谢谢!

you could try this way: 您可以这样尝试:

###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

Leaving the default WordPress instructions you should not have any problem, let me know 保留默认的WordPress指示,您应该没有任何问题,请告诉我

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

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