.htaccess 如何将2个重定向合并为一个,https +删除URL的尾随斜杠?

ff29svar  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(123)

我的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 (&param=value)

它重定向到https,然后重定向到不带斜杠的url,然后重写一个不带索引的干净url等。
我想知道,如果我输入http://www.example.com/somepage/,如何在一次重定向而不是多次重定向中重定向到https://example.com/somepage

7vux5j2d

7vux5j2d1#

我想知道,如果我输入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]

相关问题