使用.htaccess删除部分URL

时间:2014-06-10 08:58:38

标签: apache .htaccess mod-rewrite url-rewriting

我正在尝试重写部分网址但到目前为止没有结果......

我的网址看起来像这样(每个网页的name细分受众群不同):

www.example.com/gallery/name/about/page.html

并且在重写之后应该是这样的:

www.example.com/about/page.html

我正在尝试重写,但它无法正常工作

RewriteRule ^gallery/([^/]+)/about/page.html$ /about/page.html? [R=301,L]

我的整个htaccess:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   RewriteEngine On
   RewriteBase /gallery
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?kohana_uri=$1 [QSA,PT,L]
   RewriteRule ^$ index.php?kohana_uri=$1 [QSA,PT,L]
   RewriteRule ^index.php/(.*) $1 [QSA,R,L]
   RewriteRule ^gallery/([^/]+)/about/page.html$ /about/page.html? [R=301,L]
 </IfModule>
  php_value eaccelerator.enable 0
  php_value xcache.cacher off
  php_value xcache.optimizer off

1 个答案:

答案 0 :(得分:0)

以这种方式使用您的代码:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   RewriteEngine On
   RewriteBase /gallery

   RewriteRule ^index.php/(.*)$ $1 [R,L]
   RewriteRule ^([^/]+)/about/page\.html$ /about/page.html? [R=301,L]

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?kohana_uri=$1 [QSA,PT,L]
 </IfModule>
  php_value eaccelerator.enable 0
  php_value xcache.cacher off
  php_value xcache.optimizer off