删除“索引”来自网址

发布于 2024-12-23 19:45:46 字数 588 浏览 0 评论 0原文

我目前正在将 URL 重写如下:

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^/?([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ articles.php?article=$2

这允许我根据当前执行的页面编写如下链接。

   www.example.com/blog/new-article
   www.example.com/gallery/new-gallery

因此,当在主页上执行时,这也会导致以下结果:

   www.example.com/index/new-post

我希望只有其中包含“index”的 URL 才能在没有它的情况下被重写,例如:

  www.example.com/index/new-post -> www.example.com/new-post

这可以完成吗?预先感谢各位!

I am currently re-writing URL's as the following:

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^/?([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ articles.php?article=$2

This allows me to write links such as the following, depending on the currently executing page.

   www.example.com/blog/new-article
   www.example.com/gallery/new-gallery

So therefore this also results in the following, when executed on the homepage:

   www.example.com/index/new-post

I would like it so that only the URLs with 'index' in them, get rewritten without it, such as:

  www.example.com/index/new-post -> www.example.com/new-post

Can this be done? Thanks in advance guys!

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

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

发布评论

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

评论(1

夏夜暖风 2024-12-30 19:45:46

在其他规则之前添加此规则:

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

Add this before your other rules:

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