Apache 重定向问题 - mod_rewrite 或 mod_alias

发布于 2024-11-03 11:39:05 字数 202 浏览 3 评论 0原文

我有一个特定的需求:

example.com/store/{location} 必须重定向到 example.com/store2/{location}

这需要重定向,而不仅仅是网址“重写”,所以我猜我需要 mod_alias,正确的?有人愿意分享正确的代码吗?我对 mod_rewrite 和 mod_alias 都有点模糊。 (我希望我问得正确)谢谢!

I have a specific need:

example.com/store/{location} must redirect to example.com/store2/{location}

And this needs to redirect, not just a url 'rewrite', so I'm guessing I need mod_alias, right? Anyone care to share the correct code for it? I'm a little fuzzy with both mod_rewrite and mod_alias. (I hope I asked this correctly) Thanks!!

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

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

发布评论

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

评论(2

長街聽風 2024-11-10 11:39:05

如果您想告诉浏览器重定向其位置,您只需使用 mod_alias

Redirect /store http://example.com/store2

如果您的意思是永久重定向,则可以使用以下内容:

RedirectPermanent /store http://example.com/store2

至于您的困惑,mod_alias 基本上是 mod_rewrite 的简单版本。引用 GreyWyvern

本质上,如果您正在执行不附加任何复杂条件的“重写”,则应该使用 mod_alias。相反,如果您想将请求重定向到不希望显示在浏览器地址栏中的文件和查询字符串,则应该使用 mod_rewrite

If you mean you want to tell the browser to redirect its location, you simply can do this with mod_alias:

Redirect /store http://example.com/store2

Or the following if you mean it's a permanent redirect:

RedirectPermanent /store http://example.com/store2

As for your confusion, mod_alias is basically a simpler version of mod_rewrite. Quoting GreyWyvern:

Essentially, if you're doing a "rewrite" which doesn't have any complex conditions attached to it, you should be using mod_alias. Conversely, if you want to redirect requests to files and query strings which you don't want displayed in the browser's address bar, you should be using mod_rewrite

嘿哥们儿 2024-11-10 11:39:05
RewriteRule ^/store/(.*)/$ store2/$1 [R=301,L]
RewriteRule ^/store/(.*)/$ store2/$1 [R=301,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文