gpt4 book ai didi

regex - .htaccess RewriteRule 保持 URL 结构

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:51:03 25 4
gpt4 key购买 nike

我当前的重写规则:

RewriteEngine on
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)?$ index.php?a=$1&v=$2&id=$3 [L]

上面的结果很好,所以我可以像这样格式化 URL

domain.com/a/b/c

我也想添加域切换,所以我想要的结果是

当您使用 domain.com/a/b/c 访问它时,sub.domain.com/a/b/c

目前这是我尝试过的

RewriteEngine on
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)?$ index.php?a=$1&v=$2&id=$3 [L]
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule (.*)$ http://sub.domain.com/ [R=301,L]

但是这样做的结果是

http://sub.domain.com/a=a&v=b&id=c

需要

http://sub.domain.com/a/b/c

感谢您的帮助!

最佳答案

反转规则的顺序:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule (.*)$ http://sub.domain.com/$1 [R=301,L]

RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)?$ index.php?a=$1&v=$2&id=$3 [L,QSA]

确保在清除浏览器缓存后进行测试。

关于regex - .htaccess RewriteRule 保持 URL 结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31444025/

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