2013-08-16 183 views
0

我想從網站的url中刪除'articles'和'artificial'文件夾,但是當我嘗試將重寫規則引入.htaccess文件時,我收到錯誤。url重寫刪除文件夾.htaccess

http://www.example.com/articles/artificial/are_string_beans_all_right_on_the_candida_diet.php

試圖轉換

http://www.example.com/are_string_beans_all_right_on_the_candida_diet.php

這裏是我的.htaccess文件

DirectoryIndex index.php 
AddDefaultCharset utf-8 

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ 
RewriteCond %{HTTPS}s ^on(s)| 
RewriteRule^http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

RewriteRule ^index\.php/?$/[L,R=301,NC] 
RewriteRule ^((?!articles/artificial).*)$ articles/artificial/$1 [NC,L] 

回答

0

的問題應該是最後一條規則的當前版本:你需要什麼是負面看任何東西有文章不preceede /人工

正則表達式應該是:

((?<!(articles/artificial)).*) 

但這probabilly不會因爲工作*是可變長度(見regex look arrounds

一個解決辦法是更換負面看待後面積極向前看,允許可變長度。所以你的規則可能是:

RewriteRule ^(?!.*?articles/artificial.*?)(.*)$ /articles/artificial/$1