2011-09-19 134 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

相关问题