url重写删除文件夹.htaccess

时间:2013-08-16 11:11:18

标签: php apache url url-rewriting

我想从网站的网址中删除“文章”和“人工”文件夹,但是当我尝试将重写规则引入.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]

1 个答案:

答案 0 :(得分:0)

问题应该放在最后一条规则上:你需要的是负面看法,即任何不在文章/人工之前的东西

正则表达式应该是:

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

但是这个概率不起作用,因为。*是可变长度的(见regex look arrounds

一个解决方案可能是用一个允许可变长度的正面向前取代背后的负面外观。所以你的规则可能是:

RewriteRule ^(?!.*?articles/artificial.*?)(.*)$ /articles/artificial/$1
相关问题