2014-09-24 128 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

相关问题