我想重定向所有的HTTP请求到https,并且所有WWW要求非www [英] I want to redirect all http requests to https, and all www requests to non-www
问题描述
下面是我目前的.htaccess文件:
Here is my current .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php
</IfModule>
我要重定向所有的HTTP请求到https,并且所有WWW要求非www,所有文件请求到index.php
I want to redirect all http requests to https, and all www requests to non-www, and all file requests to index.php
例如:
http://www.example.com 到的 https://example.com
https://www.example.com 到的 https://example.com
http://example.com/file.php 到的 https://example.com/index.php
一切似乎是工作以外的WWW部分..任何帮助吗?
Everything seems to be working except the www part.. Any help please?
推荐答案
您可以添加处理WWW部分其他规则
You can add an additional rule dealing with the www part
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [L,R]
借助 的RewriteCond
捕获 WWW之后的一切。
并使用了的 重写规则
为%1
。
当一切都按你期望的那样,你可以修改研究
到 R = 301
。
When everything works as you expect, you can change R
to R=301
.
永远不要的测试与 301
启用,看到这个答案
提示调试的.htaccess重写规则的
了解详细信息。
Never test with 301
enabled, see this answer
Tips for debugging .htaccess rewrite rules
for details.
这篇关于我想重定向所有的HTTP请求到https,并且所有WWW要求非www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!