[英]url rewrites removing folders .htaccess
我想從網站的網址中刪除“ articles”和“ artificial”文件夾,但是當我嘗試將重寫規則引入.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]
問題應該在最后一條規則上:您所需要的是背后的負面表情,即沒有任何文章/人工文章之前的內容
正則表達式應為:
((?<!(articles/artificial)).*)
但是這個概率不起作用,因為。*是可變長度的(請參閱regex look arrounds )
一種解決方案是用允許變化長度的前方正面外觀替換背后的負面外觀。 因此,您的規則可能是:
RewriteRule ^(?!.*?articles/artificial.*?)(.*)$ /articles/artificial/$1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.