0

我想从我网站的 url 和 php 扩展名中删除这两个文件夹:“folder1s”和“folder2”,但它对我的 .htaccess 文件不起作用。

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

兑换

http://www.example.com/are-string-beans-all-right-on-the-candida-diet/

这是我的 .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 ^((?!folder1/folder2).*)$ folder1/folder2/$1 [NC,L]
4

2 回答 2

2

如果您使用 RewriteCond,您正在尝试做的事情可以轻松完成

# Doesn't begin with folder1/folder2
RewriteCond %{REQUEST_URI} !^/folder1/folder2/
RewriteRule ^(.*)$ /folder1/folder2/$1 [L]

但是,这不会将请求重定向http://domain.com/folder1/folder2/filehttp://domain.com/file. 你需要一个单独的规则。

于 2013-08-16T14:51:25.423 回答
0

您可以使用 url 路由功能来执行此操作。

$route['are-string-beans-all-right-on-the-candida-diet'] = "folder1/folder2/are_string_beans_all_right_on_the_candida_diet.php";
于 2013-08-16T14:46:29.070 回答