gpt4 book ai didi

.htaccess - .htaccess 是否可以使用 3 个相同的参数?

转载 作者:行者123 更新时间:2023-12-04 03:24:43 26 4
gpt4 key购买 nike

到目前为止,

@anubhava@RavinderSingh13 极大地帮助了我更多地了解 .htaccess 和重写规则。然而,即使第一条规则(带有一个参数:$id)和第二条规则(带有两个参数:$id$name>) 用于重写 url,我尝试使用两个参数($id$class)的第三条规则失败了,并且不会重写最终的 url。到目前为止,以下是我的整个文件。我想补充一点,$class参数的格式是a-classb-class等,所以也许可能是重写不起作用的贡献者?感谢您帮助我继续学习至今!

RewriteEngine on
--1st rule with one parameter: $id--
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} id=([0-9]+) [NC]
RewriteRule ^file\.php$ /directory/%1? [R=301,L,NC]
RewriteRule ^directory/(\d+)/?$ /directory/file.php?id=$1 [L,QSA,NC]

--2nd rule with two parameters: $id and $name--
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/file\.php\?id=(\d+)&name=(\S+)\s [NC]
RewriteRule ^ /directory/%1/%2? [R=301,L]
RewriteRule ^directory/(\d+)/(.*)/?$ /directory/file.php?id=$1&name=$2 [NC,L,QSA]

--My attempt at the third rule following the example from the second, but this rule fails. Parameters are $id and $class--
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/file\.php\?id=(\d+)&class=(\S+)\s [NC]
RewriteRule ^ /directory/%1/%2? [R=301,L]
RewriteRule ^directory/(\d+)/(.*)/?$ /directory/file.php?id=$1&class=$2 [NC,L,QSA]

最佳答案

使用您展示的样本并考虑到类词将始终出现在您的第 3 个 url 中,请尝试遵循规则。另外你不需要多次写 RewriteEngine ON,只需要 1 次启动文件就足够了。

RewriteEngine on
##1st rule with one parameter: $id--
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} id=([0-9]+) [NC]
RewriteRule ^file\.php$ /directory/%1? [R=301,L,NC]
RewriteRule ^directory/(\d+)/?$ /directory/file.php?id=$1 [L,QSA,NC]

##Parameters are $id and $class
RewriteCond %{THE_REQUEST} \s/file\.php\?id=(\d+)&class=(\w+-class)\s [NC]
RewriteRule ^ /directory/%1/%2? [R=301,L]
RewriteRule ^directory/(\d+)/(\w+-class)/?$ /directory/file.php?id=$1&class=$2 [NC,L,QSA]


##Rule with two parameters: $id and $name--
RewriteCond %{THE_REQUEST} \s/file\.php\?id=(\d+)&name=(\S+)\s [NC]
RewriteRule ^ /directory/%1/%2? [R=301,L]
RewriteRule ^directory/(\d+)/(.*)/?$ /directory/file.php?id=$1&name=$2 [NC,L,QSA]

关于.htaccess - .htaccess 是否可以使用 3 个相同的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67798980/

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