简体   繁体   English

网址重写删除文件夹.htaccess

[英]url rewrites removing folders .htaccess

I want to remove 'articles' and 'artificial' folders from a site's urls, but when I try to introduce rewrite rules into .htaccess file I am receiving errors. 我想从网站的网址中删除“ articles”和“ artificial”文件夹,但是当我尝试将重写规则引入.htaccess文件时,却收到错误消息。

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

trying to convert 试图转换

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

here is the current version of my .htaccess file 这是我的.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]

The problem should be on the last rule: what you need is a negative look behind ie anything not preceede with articles/artificial 问题应该在最后一条规则上:您所需要的是背后负面表情,没有任何文章/人工文章之前的内容

The regex should be: 正则表达式应为:

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

But this probabilly does not work since the .* is variable length (see regex look arrounds ) 但是这个概率不起作用,因为。*是可变长度的(请参阅regex look arrounds

A solution could be replacing the negative look behind with a positive look ahead that allows for variable length. 一种解决方案是用允许变​​化长度的前方正面外观替换背后的负面外观。 So your rule could be: 因此,您的规则可能是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM