htaccess url 重写带问号

发布于 2025-01-05 02:28:02 字数 407 浏览 1 评论 0原文

我在 .htaccess 中遇到问题,特别是在重定向方面。

我想重写这个 url:

http://www.domain.com/?mod=country

to

http://www.domain.com/country

我已经尝试过这个 .htaccess 代码:

RewriteEngine on
RewriteRule ^\?mod=(.*)$ $1

我尝试在没有问号字符的情况下对其进行处理,并且它工作正常。 我已经逃脱了问号,因为它是特殊字符的一部分,但我仍然无法让它工作。

你能告诉我我错过了什么吗?

I'm having a problem in .htaccess, specifically on redirection.

I wanted to rewrite this url:

http://www.domain.com/?mod=country

to

http://www.domain.com/country

I already tried this .htaccess code:

RewriteEngine on
RewriteRule ^\?mod=(.*)$ $1

I tried working on it without the question mark character and it works fine.
I have escaped the question mark because it's part of the special characters, but still, I couldn't get it work.

Can you tell what I'm missing?

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

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

发布评论

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

评论(1

み青杉依旧 2025-01-12 02:28:02

直接将您的要求转化为重写规则:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^mod=(.*)$
RewriteRule ^$ %1

但您可能想要更灵活的东西,例如:

RewriteEngine On
RewriteCond %{QUERY_STRING} (?:^|&)mod=([^&]+)
RewriteRule /?(.*) %1/$1 [QSA]

这些规则适用于您的域的根。

如果您想进行外部重定向,请将 R 标志添加到重写规则中。

Directly translating your requirements to rewrite rules:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^mod=(.*)$
RewriteRule ^$ %1

But you probably want something more flexible like:

RewriteEngine On
RewriteCond %{QUERY_STRING} (?:^|&)mod=([^&]+)
RewriteRule /?(.*) %1/$1 [QSA]

These rules apply to the root of your domain.

If you want to do an external redirect add the R flag to the rewrite rule.

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