使用 mod_rewrite 清理 URL

发布于 2024-10-07 15:10:00 字数 531 浏览 0 评论 0原文

我正在尝试使用 mod_rewrite 清理我的 URL。

在我的网址中,我有:

http://blog.com/cat/post1/index.html
http://blog.com/cat/post2/index.html
http://blog.com/cat/post3/index.html
etc....

.htaccess

RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\ /.*/index\.(php|html)\ HTTP
RewriteRule (.*)index\.(php|html)$ /$1 [R=301,L]

当我输入上述网址时,我得到:

http://blog.com/post1/

但我想:

http://blog.com/cat/post1/

我在这里做错了什么???

I am trying to cleanup my URL using mod_rewrite.

In my URLs I have:

http://blog.com/cat/post1/index.html
http://blog.com/cat/post2/index.html
http://blog.com/cat/post3/index.html
etc....

.htaccess

RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\ /.*/index\.(php|html)\ HTTP
RewriteRule (.*)index\.(php|html)$ /$1 [R=301,L]

When I enter the URL mentioned above I get:

http://blog.com/post1/

But I want:

http://blog.com/cat/post1/

What am I doing wrong here???

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

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

发布评论

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

评论(1

静谧 2024-10-14 15:10:00
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\ /.*/index\.(php|html)\ HTTP
RewriteRule (.*) http://blog.com/cat/$1 [R=301, L]
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\ /.*/index\.(php|html)\ HTTP
RewriteRule (.*) http://blog.com/cat/$1 [R=301, L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文