.htaccess - 定位除索引之外的所有内容(使用干净的 URL)
.htaccess - target everything EXCEPT the index (with using clean URLs)
我的代码是这样的:
<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}/ [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= [QSA,L]
除了主页,我想在所有地方强制使用 SSL。因此,我需要查看请求的地址是否等于“/”
我不太明白。我尝试了以下所有方法,但我似乎需要一个 htaccess 专家:
RewriteCond !^(/)
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= [QSA,L]
我的代码是这样的:
<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}/ [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= [QSA,L]
除了主页,我想在所有地方强制使用 SSL。因此,我需要查看请求的地址是否等于“/”
我不太明白。我尝试了以下所有方法,但我似乎需要一个 htaccess 专家:
RewriteCond !^(/)
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= [QSA,L]