我的 htaccess 實際上看起來像:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com(.)*$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^(.*)/$ /$1 [R=301,L]
RewriteRule ^([0-9a-zA-Z/\ -] )(?:&([0-9a-zA-Z&=_\ -] ))?$ index.php?action=$1&$2 [L]
# $1 : route name and framework parameters
# $2 : classic $_GET parameters (¶m=value)
它重定向到https,然后重定向到不帶斜杠的url,然后重寫一個沒有索引的干凈url等。
我想知道,如果我輸入http://www.example.com/somepage/
,如何重定向到https://example.com/somepage
單個重定向而不是多個?
uj5u.com熱心網友回復:
我想知道,如果我輸入
http://example.com/somepage/
,如何重定向到https://example.com/somepage
一個重定向而不是兩個?
您可以為此使用這個單一的重定向規則:
DirectoryIndex index.php
RewriteEngine On
# add https, remove www and remove trailing slash in same rule
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{REQUEST_URI} /$
RewriteCond %{HTTP_HOST} ^(?:www\.)?(. )$ [NC]
RewriteRule ^(.*?)/?$ https://%1/$1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php?action=$0 [L,QSA]
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/505676.html
標籤:.htaccess 重定向 改写 https url重写