我正在寻找一些可能被认为是终极的。htaccess重写规则的网站与SSL和使用非www(裸)域。
我正在寻找一个.htaccess规则
一
-
http://www.example.com
https://example.com
(http www到https非www)
-
http://example.com
>
(http-non-www到https-non-www)
-
https://www.example.com
>
(https-www到https-non-www)
-
https://example.com/tester
>
https://example.com/tester/
(如果缺少,则添加尾随斜杠,以便不允许两个URL同时工作)
-
https://example.com/tester//
>
https://example.com/tester/
(去掉多余的尾部斜杠)
-
http://www.example.com/image.jpg
https://example.com/image.jpg
(还可以捕获通过URL栏直接访问的资产)
在上面的例子中,我试图找到一条规则,将所有这些规则都规则化,以修复url结尾处的斜杠(在过去,我见过同时适用于这两者的规则)
/tester
/tester/
我找到的其他规则适用于上述所有案例,
对于通过浏览器URL栏直接访问的文件,如图像等。在这些情况下,重定向不会重写URL。通过浏览器直接访问的资产仍应使用非www重写为https。
RewriteCond
RewriteRule
不需要将实际的域硬编码到它们中。