Apache htaccess帮助,需要强制www、https和删除index.php
我的htaccess文件中有一个重写,它从url中删除index.phpApache htaccess帮助,需要强制www、https和删除index.php,apache,.htaccess,mod-rewrite,https,litespeed,Apache,.htaccess,Mod Rewrite,Https,Litespeed,我的htaccess文件中有一个重写,它从url中删除index.php RewriteEngine on RewriteCond $1 !^(images|media|system|themes|_css|_js|favicon\.ico|robots\.txt|cert\.html|index\.php) [NC] RewriteRule ^(.*)$ /index.php/$1 [L] 除此之外,我还想强制www和https用于任何没有这两个选项的请求 因此,最终所有URL都应该如下所示
RewriteEngine on
RewriteCond $1 !^(images|media|system|themes|_css|_js|favicon\.ico|robots\.txt|cert\.html|index\.php) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
除此之外,我还想强制www
和https
用于任何没有这两个选项的请求
因此,最终所有URL都应该如下所示:https://www.example.com/whatever/something/
;出于搜索引擎优化的目的,如果一个url没有标记,它应该301重定向到它的正确版本,例如:
http://example.com/about/
301 redirect to
https://www.example.com/about/
我希望能得到一些帮助,谢谢 强制WWW:
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L] # include 's' here to force ssl in addition to www
强制SSL:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
删除“index.php”:
谢谢,到目前为止,这似乎效果不错。如果我在浏览器中点击,我会得到证书不可信错误,因为证书只针对www。有什么办法吗?@mjr获取同时覆盖
domain.com
和www.domain.com
的证书。。或者更昂贵的通配符证书(将覆盖所有子域)。不幸的是,必须先建立安全通道(SSL),才能启动HTTPS的HTTP部分。换句话说,在连接完全建立之前,重写规则不会执行。@mjr我提交了一个对已接受答案的编辑,该答案将解决您的问题。当您键入类似www.example.com/example
的内容时,第一个代码段不会强制SSL。“forcessl:”下的第二个代码片段似乎对我来说非常适合。
RewriteCond %{THE_REQUEST} /index.php HTTP
RewriteRule (.*)index.php$ /$1 [R=301,L]