2016-03-17 91 views
1

我創建一個PHP項目,以及文件夾結構看起來是這樣的:PHP /的.htaccess - 重定向到指定的文件夾

includes/ 
pages/ 
config/ 

從理論上講,所有的頁面將進入pages文件夾。但是,每當有人訪問該網站時,在特定頁面上:(012)www.mysite.com/help我想讓它看看pages/文件夾,而不是認爲它位於文檔的根目錄。

我能做到這一點使用PHP /的.htaccess - 我用Google搜索這個問題,並不能看到任何相關的信息來源

回答

1

您可以使用/root/.htaccess以下規則:

RewriteEngine on 

#if "/document_root/pages/foo" is an existent file 
RewriteCond %{DOCUMENT_ROOT}/pages/$1 -f 
#rewrite /foo to /pages/foo 
RewriteRule ^(.*)$ /pages/$1 [NC,L] 
0

的.htaccess

RewriteEngine on 
RewriteRule ^/?help/?(.*) /pages/$1 [L]