.htaccess重定向仅将特定的UTF-8子域URL到其子域
我有:
https://Restoran.Grupacija.com/?ćumur
需要重定向到:
https://Restoran.Grupacija.com/
该指令在根文件夹中的.htaccess文件中,但是它不起作用:
Redirect 301 "^/%3Fćumur" https://Restoran.Grupacija.com
我也尝试过,但它也不起作用:
Redirect 301 "^/%3F%C4%87umur" https://Restoran.Grupacija.com
我的.htaccess file is < /em> UTF-8。
I have:
https://Restoran.Grupacija.com/?ćumur
Which needs to be redirected to:
https://Restoran.Grupacija.com/
This directive is in .htaccess file in the Root Folder, but it does not work:
Redirect 301 "^/%3Fćumur" https://Restoran.Grupacija.com
I have also tried this, but it does not work either:
Redirect 301 "^/%3F%C4%87umur" https://Restoran.Grupacija.com
My .htaccess file is UTF-8 already.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
mod_alias
redirect
指令仅匹配URL路径,这特别排除了查询字符串。 (但是,redirect
使用正则匹配的指示匹配也不是使用简单的前缀匹配。代码>
RewriteCond
指令中的服务器变量。请注意,浏览器/用户代理将URL编码
c
为%C4%87
在HTTP请求中,QUERY> QUERY_STRING
Server Variable不是%编码,因此我们需要匹配编码的请求。严格来说,%c4
和%
都是有效的编码。我假设您不需要明确检查所需的主机名,除非此查询字符串在您的服务器收到的另一个主机名上有效?
例如,要根据要求执行重定向,以下内容需要在任何现有重写之前靠近
.htaccess
文件的顶部。QSD
(查询字符串丢弃)标志从重定向响应中删除查询字符串。首先用302(临时)重定向测试,以避免潜在的缓存问题。
(您不需要重复
rewriteEngine
指令,如果这已经发生在.htaccess
文件中。)。The mod_alias
Redirect
directive matches the URL-path only, which notably excludes the query string. (However, neither does theRedirect
directive match using a regex, it uses simple prefix-matching instead.)To match the query string you need to use mod_rewrite instead and match against the
QUERY_STRING
server variable in aRewriteCond
directive.Note that the browser/user-agent will URL encode the
ć
as%C4%87
in the HTTP request and theQUERY_STRING
server variable is not %-decoded, so we need to match the encoded request. Strictly speaking, both%C4
and%c4
are valid encodings.I'm assuming you don't need to explicitly check the requested hostname, unless this query string could be valid on another hostname that your server receives?
For example, to perform the redirect as requested, the following would need to go near the top of your
.htaccess
file before any existing rewrites.The
QSD
(Query String Discard) flag removes the query string from the redirect response.Test first with a 302 (temporary) redirect to avoid potential caching issues.
(You do not need to repeat the
RewriteEngine
directive if this already occurs in your.htaccess
file.)