尝试 mod_rewrite 目录

发布于 2025-01-04 14:08:41 字数 436 浏览 2 评论 0原文

我正在尝试使用 httpd 进行 mod_rewrite

我希望源:

www.foo.bar.com/abc/

转到目标:

www.foo.bar.com/def/

所以我已经到达:

RewriteRule ^abc/([^/\.]+).$ def/$1 [L]

但我不仅希望它用于该页面,我还希望该 url 之后的所有后续页面也能重写。

示例 www.foo.bar.com/abc/blahblahblah1.html 转到 www.foo.bar.com/def/blahblahblah1.html

问题是我不我认为这是对的,因为它似乎不起作用。

Im trying to mod_rewrite using httpd

I want Source:

www.foo.bar.com/abc/

to go to Destination:

www.foo.bar.com/def/

So I've arrived at:

RewriteRule ^abc/([^/\.]+).$ def/$1 [L]

But i don't only want it for that one page, i want all subsequent pages following the url to rewrite also.

Example www.foo.bar.com/abc/blahblahblah1.html to goto www.foo.bar.com/def/blahblahblah1.html

The problem is I don't think this is right, because it doesn't seem to work.

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

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

发布评论

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

评论(2

甜点 2025-01-11 14:08:41
RewriteEngine On
RewriteRule ^/abc/(.*)$ /def/$1

稍微简化了一下,因为我不确定为什么你要在任何给定的“/”或“.”处停止重写。 - 可能会导致一些奇怪的行为。

这是假设您在 .htaccess (在文档根目录中)而不是 httpd-vhosts.conf 中执行重写(在两者之间的路径)。

RewriteEngine On
RewriteRule ^/abc/(.*)$ /def/$1

Simplified it a little as I'm not sure why you're stopping the rewrite at any given '/' or '.' - could lead to some odd behaviour.

This is assuming you're performing the rewrite in .htaccess (in the document root) rather than, say, httpd-vhosts.conf (there may be slight differences in the paths between the two).

焚却相思 2025-01-11 14:08:41
RewriteEngine On
RewriteBase   /

RewriteRule ^abc/(.*)   def/$1               [L,NS]

这假设 .htaccess 位于您的 DOCROOT 中。始终指定一个基础——即 / 代表文档根目录。不要包含每个目录的前导 /(在 .htaccess 中)。

RewriteEngine On
RewriteBase   /

RewriteRule ^abc/(.*)   def/$1               [L,NS]

This assumes that the .htaccess is in your DOCROOT. Always specify a base -- which is / for your document root. Do not include the leading / for Per Directory (in .htaccess).

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