HTACCESS 重定向

发布于 2024-09-16 00:58:54 字数 236 浏览 4 评论 0原文

在我的 htaccess 文件中,我有以下两条规则。我想让第二个发生的条件是第一个不匹配。目前,他们都跑了。有什么办法可以避免碰撞吗?

redirect 301 /lorem/ipsum-keyword.html /lorem/dolorem-keyword.html
RewriteRule (.*)-keyword.html$  /dir/file.php?param=$1

提前致谢。

In my htaccess file, I have the following two rules. I would like to make the second one occur on the condition that the first one doesn't match. Currently, they both get run. Is there any way around the collision?

redirect 301 /lorem/ipsum-keyword.html /lorem/dolorem-keyword.html
RewriteRule (.*)-keyword.html$  /dir/file.php?param=$1

Thanks in advance.

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

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

发布评论

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

评论(2

遇到 2024-09-23 00:58:54

两者都使用 mod_rewrite 并使用 L 选项以确保不会发生进一步的重写。像这样的事情:

RewriteRule ^lorem/ipsum-keyword.html$ http://yourdomain.com/lorem/dolorem-keyword.html [R=301,L]
RewriteRule (.*)-keyword.html$  /dir/file.php?param=$1

Use mod_rewrite for both and use the L option to ensure that no further rewriting occurs. Something like this:

RewriteRule ^lorem/ipsum-keyword.html$ http://yourdomain.com/lorem/dolorem-keyword.html [R=301,L]
RewriteRule (.*)-keyword.html$  /dir/file.php?param=$1
网白 2024-09-23 00:58:54

您可以对 301 使用重写规则并添加 L 标志,因此它将忽略以下规则。

我无法测试它,但这应该有效:

RewriteRule /lorem/ipsum-keyword.html$  /lorem/dolorem-keyword.html [R=301,L]
RewriteRule (.*)-keyword.html$  /dir/file.php?param=$1

You might use a rewrite rule for the 301 and add the L flag, so it will ignore the following rules.

I can't test it, but this should work:

RewriteRule /lorem/ipsum-keyword.html$  /lorem/dolorem-keyword.html [R=301,L]
RewriteRule (.*)-keyword.html$  /dir/file.php?param=$1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文