如何使用 htaccess 重定向文件夹的所有地址?

发布于 2024-09-30 05:20:55 字数 341 浏览 0 评论 0原文

有人可以帮我修改这段代码吗?我不知道如何修改 htaccess。

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteRule (some_folder/.*) $1 [L] # adjust the regex to what you want.

    # normal cake rules
    RewriteRule ^$ webroot/ [L]
    RewriteRule (.*) webroot/$1 [L]
 </IfModule>

我想将所有地址 blog/* 重定向到 blog/

Can some one help me modify this code. I am not sure how to modify htaccess.

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteRule (some_folder/.*) $1 [L] # adjust the regex to what you want.

    # normal cake rules
    RewriteRule ^$ webroot/ [L]
    RewriteRule (.*) webroot/$1 [L]
 </IfModule>

I wanna redirect all address blog/* to blog/

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

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

发布评论

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

评论(1

泛泛之交 2024-10-07 05:20:55

您可能想要:

RewriteRule ^blog/?(.*)$ blog/ [L]

不过,我不确定您为什么要忽略部分 URL。您想强制将地址设置为 blog/ 而不是透明重定向吗?使用 [R] 而不是 [L]

要覆盖 CakePHP 重定向,您可以尝试

RewriteRule ^/blog(/?.*)$ /blog$1 [L]

在之前插入:

RewriteRule (.*) webroot/$1 [L]

You probably want:

RewriteRule ^blog/?(.*)$ blog/ [L]

I'm not sure why you'd want to ignore part of the URL though. Do you want to force the address to blog/ instead of a transparent redirect? Use [R] instead of [L]

To override CakePHP redirects, you could try inserting:

RewriteRule ^/blog(/?.*)$ /blog$1 [L]

before

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