htaccess帮助,需要强制www,https,并删除index.php

时间:2011-07-27 16:08:50

标签: 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]

除此之外,我还要强制wwwhttps用于任何没有任何请求的请求。

所以最终所有网址都应如下所示:https://www.example.com/whatever/something/;对于搜索引擎优化的目的,如果一个网址错过了该标记,它应该301重定向到它的正确版本,例如:

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

非常乐意帮助实现这一目标,谢谢!

1 个答案:

答案 0 :(得分:24)

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

RewriteCond %{THE_REQUEST} /index.php HTTP
RewriteRule (.*)index.php$ /$1 [R=301,L]