下面是我目前的.htaccess文件:
Here is my current .htaccess file:
<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTPS} !=on RewriteRule ^ %{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
例如:
www.example 到的 example
www.example 到的 example
example/file.php 到的 example/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 ^ %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
发布评论