.htaccess重定向仅将特定的UTF-8子域URL到其子域

发布于 2025-01-25 13:26:08 字数 432 浏览 2 评论 0原文

我有:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惯饮孤独 2025-02-01 13:26:08

mod_alias redirect指令仅匹配URL路径,这特别排除了查询字符串。 (但是,redirect使用正则匹配的指示匹配也不是使用简单的前缀匹配

。代码> RewriteCond指令中的服务器变量。

请注意,浏览器/用户代理将URL编码c%C4%87在HTTP请求中,QUERY> QUERY_STRING Server Variable不是%编码,因此我们需要匹配编码的请求。严格来说,%c4都是有效的编码。

我假设您不需要明确检查所需的主机名,除非此查询字符串在您的服务器收到的另一个主机名上有效?

例如,要根据要求执行重定向,以下内容需要在任何现有重写之前靠近.htaccess文件的顶部。

RewriteEngine On

RewriteCond %{QUERY_STRING} ^%[cC]4%87umur$
RewriteRule ^$ / [QSD,R=301,L]

QSD(查询字符串丢弃)标志从重定向响应中删除查询字符串。

首先用302(临时)重定向测试,以避免潜在的缓存问题。

(您不需要重复rewriteEngine指令,如果这已经发生在.htaccess文件中。)。

The mod_alias Redirect directive matches the URL-path only, which notably excludes the query string. (However, neither does the Redirect 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 a RewriteCond directive.

Note that the browser/user-agent will URL encode the ć as %C4%87 in the HTTP request and the QUERY_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.

RewriteEngine On

RewriteCond %{QUERY_STRING} ^%[cC]4%87umur$
RewriteRule ^$ / [QSD,R=301,L]

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文