2014-09-24 182 views
0

我認爲在我的htaccess代碼中有一些問題,但我無法弄清楚。使用Htacess刪除文件夾名稱

我需要的是。

1)從像www.domain.com/index代替www.domain.com/index.php

2的地址PHP擴展)卸下文件夾名稱。我的網站文件存儲在一個名爲public的文件夾中。我想刪除它。 www.domain.com/public/index.php到www.domain.com/index

我寫了下面的代碼,請讓我知道這是什麼錯誤。

# This will hide the folder name public and the php text 
Options +FollowSymLinks -MultiViews 
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteCond %{REQUEST_URI} !/$ 
RewriteRule (.*) $1\.php [L] 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+public/([^\s]+) [NC] 
RewriteRule^%1 [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
# if you face any problem than try to uncomment the below line and delete the line after it 
RewriteRule (?!^public/)^(.*)$ public/$1 [L,NC] 
+0

可能重複:[刪除擴展名爲.php與的.htaccess(http://stackoverflow.com/questions/4026021/remove-php -extension-with-htaccess) – Azrael 2014-09-24 06:42:23

+0

1)使用'選項+多視圖' – Phil 2014-09-24 06:42:52

+0

有人可以告訴我爲什麼這是downvoted? – user3477550 2014-09-24 07:15:36

回答

0

你可以有你的規則是這樣的:

# This will hide the folder name public and the php text 
Options +FollowSymLinks -MultiViews 
RewriteEngine On 
RewriteBase/

RewriteCond %{THE_REQUEST} \s/+public/(\S+) [NC] 
RewriteRule^%1 [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
# if you face any problem than try to uncomment the below line and delete the line after it 
RewriteRule ^((?!public/).*)$ public/$1 [L,NC] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/public/$1\.php -f [NC] 
RewriteRule ^(.+?)/?$ $1.php [L] 
+0

謝謝anubhava,但我檢查了這一點。它不工作。我編輯過的文本請閱讀... – user3477550 2014-09-24 07:30:29

+0

哪個網址不起作用?你還有一個'/ public/.htaccess'文件嗎? – anubhava 2014-09-24 07:33:42

+0

當您在瀏覽器中輸入「www.domain.com/index」時會發生什麼? – anubhava 2014-09-24 07:41:05

相關問題