从URL中删除“索引”

时间:2012-01-01 14:08:15

标签: apache .htaccess mod-rewrite

我目前正在重写网址,如下所示:

   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'的网址时才会被重写,例如:

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

可以这样做吗?先谢谢你们!

1 个答案:

答案 0 :(得分:0)

在您的其他规则之前添加:

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