特定的HTACCE重定向异常

发布于 2025-01-31 11:45:25 字数 487 浏览 1 评论 0原文

我已经在.htaccess特定条件的文件中创建了一个重定向:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^page/(.*) /clanky/?sf_paged=$1 [R=301,L]
</IfModule>

示例:

有人单击此链接:https://example.com/page/2/2/重定向到:https://example.com/clanky/?sf_paged=2/

此场景完美效果。

现在,如果链接为:https://example.com/page/2/?s=zemedelec - (排除条件应为/ ?s =),在这种情况下,我不想使用任何重定向。

有什么想法,如何使这个例外?

I have created a redirection in .htaccess file for specific condition:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^page/(.*) /clanky/?sf_paged=$1 [R=301,L]
</IfModule>

Example:

someone clicks on this link: https://example.com/page/2/ and they will be redirected to: https://example.com/clanky/?sf_paged=2/

This scenario works perfectly.

Now I need to make an exception for the case if a link will be: https://example.com/page/2/?s=zemedelec - (the excluding condition should be /?s=), in this case I don't want to use any redirection.

Any idea, how to make this exception?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

谁把谁当真 2025-02-07 11:45:25

为了在您的现有规则上进行例外,查询字符串以URL参数s =开始,然后您可以添加以下条件rewriteCond指令):

RewriteCond %{QUERY_STRING} !^s=
RewriteRule ^page/(.*) /clanky/?sf_paged=$1 [R=301,L]

当查询字符串不以s =开头时,否定条件!^s =是成功的。

(排除条件应为/?s =

以上未明确检查URL路径是否在斜线中结束,因此它也将排除表单> https://的请求。 xxx.cz/page/2?s=zemedelec

To make an exception on your existing rule for when the query string starts with the URL parameter s= then you can add the following condition (RewriteCond directive):

RewriteCond %{QUERY_STRING} !^s=
RewriteRule ^page/(.*) /clanky/?sf_paged=$1 [R=301,L]

The negated condition !^s= is successful when the query string does not start with s=.

(the excluding condition should be /?s=)

The above does not explicitly check that the URL-path ends in a slash, so it will also exclude requests of the form https://xxx.cz/page/2?s=zemedelec.

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