gpt4 book ai didi

apache - 替换URL查询字符串中的“/”以避免htaccess中出现404

转载 作者:行者123 更新时间:2023-12-01 10:57:29 25 4
gpt4 key购买 nike

我有一个包含两个参数的网址,并使用此参数在htaccess文件中重写了它们

RewriteRule ^subscriber/([^/.]+)/([^/.]+)/?$ subscriber/index.php?id=$1&name=$2 [NC,L]

在某些情况下,该名称包含一个“/”,浏览器将其视为另一个参数,并为我提供了404页。有没有办法使用htaccess文件将“/”替换为其他内容?

最佳答案

尝试将其放在文档根目录的htaccess文件中:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*)name=([^&]*)/(.*)$
RewriteRule ^ %{REQUEST_URI}?%1name=%2-%3 [L]

# Change your existing rule a bit to account for the slash (plus a possible trailing slash):
RewriteRule ^subscriber/([^/.]+)/(.+?)/?$ /subscriber/index.php?id=$1&name=$2 [NC,L]

这将使URIt中的第一个“文件夹”位于 Subscriber / id参数之后,除斜杠之后的所有其他内容都将成为 name参数。然后,第一组规则反复清除 name参数,将 /替换为 -

关于apache - 替换URL查询字符串中的“/”以避免htaccess中出现404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11822773/

25 4 0
文章推荐: block - 移除 EPiServer 7 Shared Block 周围生成的
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com