2011-09-19 72 views
4

我是htaccess的新手,並且遇到了一些我需要幫助的問題。在我的網站中,我有一個文件夾(實際上是空白的),我想爲其提供來自根文件夾的內容。htaccess重寫文件夾url以顯示根文件夾中的內容

讓說的結構如下:

example.com

-folder1 

    -index.php 

    -anotherpage.php 

    -.htaccess 

所以,當有人去example.com/folder1/index.php,他會看到網址爲,但得到來自example.com/index.php的內容。如果他訪問example.com/folder1/anotherpage.php,他將從example.com/anotherpage.php獲取內容。當然,當他直接訪問example.com/index.php時,他會看到example.com/index.php。

我發現很多例子顯示相反,但不是我想要的。另外爲了澄清,我想重寫,而不是重定向,所以這個url會僞造,實際上有folder1中的頁面。

任何幫助將不勝感激。

回答

3

使用此的.htaccess在根文件夾:

# Enable mod_rewrite 
RewriteEngine on 
# ^: Start with 
# folder1: name the folder 
# (\/?): Can containt an ending slash eg: folder1/ or folder1 
# $: End with 
# [QSA]: Query string append, means you can use %name=value 
# [NC]: Non Case: Case insensitive 
# [L]: Last rule, stop if this rule match the url 
RewriteRule ^folder1(\/?)$ /index.php [QSA,NC,L] 
# (.*): Everything 
# $1: the matching filename- file must exists. 
RewriteRule ^folder1/(.*)(\/?)$ /$1 [QSA,NC,L] 
+0

不工作.... – Ferdous

+2

你在哪裏把這些規則?你能告訴我你的.htaccess嗎? –

+0

你能解釋每條線路在做什麼嗎? – User

相關問題