9

我在我的 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]

除此之外,我想对任何没有的请求强制使用wwwand 。https

所以最终所有的网址应该是这样的https://www.example.com/whatever/something/:并且出于 SEO 的目的,如果 url 错过了标记,它应该 301 重定向到它的正确版本,例如:

http://example.com/about/
301 redirect to
https://www.example.com/about/

希望有人帮助实现这一点,谢谢!

4

1 回答 1

24

强制万维网:

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”:

RewriteCond %{THE_REQUEST} /index.php HTTP
RewriteRule (.*)index.php$ /$1 [R=301,L]
于 2011-07-27T16:20:47.527 回答