2013-08-16 78 views
0

我想刪除這兩個文件夾:我的網站的url中的'folder1s'和'folder2',以及php的擴展名,但它不會對我的.htaccess文件生效。.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] 

回答

0

爲此,您可以使用URL路由功能。

$route['are-string-beans-all-right-on-the-candida-diet'] = "folder1/folder2/are_string_beans_all_right_on_the_candida_diet.php"; 
+0

嗨,它給500內部服務器錯誤。 – user2689182

2

什麼你正在嘗試做的可以輕鬆完成,如果你使用的RewriteCond

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

然而,這將不http://domain.com/folder1/folder2/file重定向請求http://domain.com/file。你需要一個獨立的規則。

+0

它給錯誤。我只想隱藏這兩個文件夾並將其重定向到http://domain.com/folder1/folder2/file – user2689182