htaccess只从url中删除文件夹

时间:2014-01-24 08:56:16

标签: apache .htaccess mod-rewrite

我试图从我的网址中只删除一个特定的文件夹。我在这里看到了许多答案,但我找不到任何能为我工作的人。 我有这个网址http://www.mydomain.com/projects/books/index.php 我想删除项目文件夹,以便我可以使用 http://www.mydomain.com/books/index.php

我在public_html文件夹中有这个.htacces:

RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)projects 
RewriteRule ^(.*)$ projects/$1 [L]

使用此代码我可以访问http://www.mydomain.com/books/index.php,但任何其他地址都会将我重定向到projcets文件夹中 例如http://www.mydomain.com显示/ projects的索引 谢谢

1 个答案:

答案 0 :(得分:0)

您可以尝试以下规则:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f    
RewriteCond %{REQUEST_URI} !^/(projects/|index\.php) [NC]
RewriteRule ^(.+)$ /projects/$1 [L]
相关问题