2011-04-06 103 views
1

我想使用.htaccess文件返回主页(index.html)如果直接访问网站(无参数)和index.php /子目录/。 ...如果其他环节使用.htaccess服务index.html或index.php

例如:

my_site.com显示的index.html

my_site.com/dir1/dir2/必须重定向与参数的index.php DIR1/DIR2 ..

请帮忙创建这个.htaccess文件

我在现有的文件这样的:

RewriteEngine叙述在

重写规则^ | $的index.php [L]

的RewriteCond%{} REQUEST_FILENAME(*)(HTML的.htm。)! -f

的RewriteCond%{} REQUEST_FILENAME!-d

重写规则^(。*)/ $的index.php [L]

我想要做的例外,提前进入现场时

感谢

回答

0

尝试这些规则.htaccess文件,其用于index.html文件:

RewriteEngine on 
Options +FollowSymlinks -MultiViews 

# to redirect my.site.com to my.site.com/index.html 
RewriteRule ^$ /index.html [R,L] 

# to redirect /dir1/dir2 to index.php?url=dir1/dir2 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{QUERY_STRING} !^url= 
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?url=$1/$2 [R,L,QSA] 
+0

谢谢你,它工作在一台服务器,但在另一个它不起作用 – Sofiane 2011-04-07 13:03:02

+0

@Sofiane:我很难猜测为什么上面的代码在1台计算机上工作,但不工作在另一台计算机上。您需要首先比较两个主机的apache配置,并查看两个中是否安装了mod_rewrite。 – anubhava 2011-04-07 13:12:49

+0

mod_rewrite安装良好,在两台服务器上工作正常,我无法验证第一台服务器(哪个.htaccess工作正常)中的Apache,因为它不是专用服务器,但它工作正常。我只需要纠正第二个.htaccess(专用服务器)让执行index.html if(mysite.com或mysite.com/index.html),并执行index.php到所有其他文件和目录(mysite.com /page1.html mysite.com/all_directories/../../,mysite.com/all_directories/index.html .....),请帮忙 – Sofiane 2011-04-07 13:54:44

相关问题