Mod Rewrite - 根据是否有 GET 参数进行重定向

发布于 2024-09-01 17:35:27 字数 436 浏览 0 评论 0原文

我想将这些 URL 重定向:

http://example.com/searchhttp://example.com/?page=search

http:// example.com/search?q=keywordhttp://example.com/?page=search&q=keyword

我试图在 .htaccess< 中使用它/strong> 但不起作用:

RewriteRule ^search$ ?page=search [nc]
RewriteRule ^search\?(.*)$ ?page=search&$1 [nc]

我做错了什么?

I want to redirect these URLs:

http://example.com/search to http://example.com/?page=search

http://example.com/search?q=keyword to http://example.com/?page=search&q=keyword

I am trying to use this in .htaccess but doesn't work:

RewriteRule ^search$ ?page=search [nc]
RewriteRule ^search\?(.*)$ ?page=search&$1 [nc]

What am I doing wrong?

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

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

发布评论

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

评论(1

离旧人 2024-09-08 17:35:27

假设您希望将请求定向到 index.php 文件,并将该文件包含在规则中。例如,

RewriteRule ^search$ index.php?page=search [L]

尝试一下。

Assuming you want to direct the request to the index.php file include the file in the rules. E.g.

RewriteRule ^search$ index.php?page=search [L]

Give it a try.

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