mod_rewrite 重定向正在附加我不想要的 url 参数

发布于 2025-01-06 12:11:25 字数 784 浏览 3 评论 0原文

我有很多旧网址需要重定向。该网站通过 mod_rewrite 规则点击 index.php?url=whatever 来工作。但是,我不希望用户在重定向的情况下看到参数:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^clients_whatever1\.html$   /  [R]
    RewriteRule  ^clients_whatever2\.html$   /client-list/whatever2  [R]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
    </IfModule>

因此,在以下情况下:

(the domain)/clients_whatever2.html

他们将被重定向到:

(the domain)/client-list/whatever2?url=/client-list/whatever2

但它应该简单地读为:

(the domain)/client-list/whatever2

如何进行重定向以便它出现在浏览器 URL 是否与其他请求一样(对于非重定向)?

I have a lot of old urls that I need to redirect. The site works by hitting an index.php?url=whatever via a mod_rewrite rule. However, I dont want the user to see the arg in the case of a redirect:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^clients_whatever1\.html$   /  [R]
    RewriteRule  ^clients_whatever2\.html$   /client-list/whatever2  [R]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
    </IfModule>

So in the case of:

(the domain)/clients_whatever2.html

they are being redirected to:

(the domain)/client-list/whatever2?url=/client-list/whatever2

but it should simply read as:

(the domain)/client-list/whatever2

How to do the redirect so that it shows up in the browser url as any other request (for a non-redirect)?

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

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

发布评论

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

评论(1

樱桃奶球 2025-01-13 12:11:25

? 附加到规则目标以删除原始查询字符串参数,即

RewriteRule ^clients_whatever1\.html$   /?  [R,L]
RewriteRule  ^clients_whatever2\.html$   /client-list/whatever2?  [R,L]

Append a ? to the rule target to drop the original query string params i.e.

RewriteRule ^clients_whatever1\.html$   /?  [R,L]
RewriteRule  ^clients_whatever2\.html$   /client-list/whatever2?  [R,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文