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

时间:2022-05-26 11:17:33

I have a rewrite in my htaccess file that removes index.php from the url

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

In addition to this, I want to force the www and https for any request that does not have either.

除此之外,我想强制www和https用于任何没有的请求。

So ultimately all urls should look like this: https://www.example.com/whatever/something/; and for SEO purposes, if a url misses the mark, it should 301 redirect to it's correct version, for example:

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

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

Would love some help accomplishing that, thanks!

非常愿意帮助完成这一切,谢谢!

1 个解决方案

#1


23  

Force WWW:

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

Force SSL:

强制SSL:

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

Remove "index.php":

删除“index.php”:

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

#1


23  

Force WWW:

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

Force SSL:

强制SSL:

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

Remove "index.php":

删除“index.php”:

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