gpt4 book ai didi

regex - .htaccess - 定位除索引之外的所有内容(使用干净的 URL)

转载 作者:太空宇宙 更新时间:2023-11-03 13:26:16 24 4
gpt4 key购买 nike

我的代码是这样的:

<IfModule mod_rewrite.c>

RewriteEngine On

# Detect Protocol
RewriteCond %{HTTPS} =on
RewriteRule ^ - [env=proto:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^ - [env=proto:http]

# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# Force WWW and correct protocol
#RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ %{ENV:PROTO}://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteRule ^\.htaccess$ - [F]
RewriteRule ^php\.ini$ - [F]

RewriteRule ^cgi-bin - [R=404]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|gif|png|js|css|swf)$
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

除了主页之外,我想在所有地方强制使用 SSL。因此,我需要查看请求的地址是否等于“/”

我不是很清楚。我尝试了以下所有方法,但我似乎需要一个 htaccess 专家:

RewriteCond $1 !^(/)
RewriteCond %{REQUEST_URI} !(/)
RewriteCond %{REQUEST_URI} !(/$)

...还有其他一些。很确定我需要在之后添加它

RewriteCond %{HTTPS} !=on

但是我被卡住了

最佳答案

您可以使用:

RewriteEngine On

# Detect Protocol
RewriteCond %{HTTPS} on
RewriteRule ^ - [env=proto:https]
RewriteCond %{HTTPS} off
RewriteRule ^ - [env=proto:http]

# Force SSL except for home page
RewriteCond %{HTTPS} off
RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Force WWW and correct protocol
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ %{ENV:PROTO}://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteRule ^\.htaccess$ - [F]
RewriteRule ^php\.ini$ - [F]
RewriteRule ^cgi-bin - [R=404]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.(jpe?g|gif|png|js|css|swf)$ [NC]
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

关于regex - .htaccess - 定位除索引之外的所有内容(使用干净的 URL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29284189/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com