如何隐藏真实index.php的路径

时间:2015-12-14 04:08:34

标签: php apache .htaccess mod-rewrite url-rewriting

我有一个web项目,其中索引文件位于深层文件夹中。

假设我的项目索引位于localhost/xxx/a/b/c/index.php,但我想将/a/b/c路径隐藏为localhost/index.php

如何编码.htaccess以及我应该把它放在哪里?

谢谢。

1 个答案:

答案 0 :(得分:2)

在public_html / .htaccess

中尝试以下操作
RewriteEngine on
#if the request is not for and existent file
RewriteCond %{REQUEST_FILENAME} !-f
#and the request is not for and existent directory
RewriteCond %{REQUEST_FILENAME} !-d
#then rewrite it to /a/b/c/request
RewriteRule ^(?:xxx/)?(.*)$ /xxx/a/b/c/$1 [NC,L]

这将在内部重定向

example.com/file.php

example.com/a/b/c/file.php
相关问题