+ -
当前位置:首页 → 问答吧 → RewriteRule 和 DirectoryIndex问题

RewriteRule 和 DirectoryIndex问题

时间:2008-10-22

来源:互联网

如何通过设置.htaccess

使下面两句都起作用?
DirectoryIndex index.html
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css|html|xml|htm)$ index.php

就是说直接用域名访问时,直接访问的是根目录下的index.html文件,而不是index.php

作者: ironcrane   发布时间: 2008-10-22

最后设置的规则 将会覆盖掉前面的同类规则

RewriteRule !\.(js|ico|gif|jpg|png|css|html|xml|htm)$ index.php
已经清晰的告诉apache 对于请求应该 指向index.php

之前的 DirectoryIndex index.html 自然就不管用了

就像 css里面

a{color:#fff}
*{color:#000}

最终页面文字颜色是黑色一样的道理

作者: yz20sui   发布时间: 2008-10-22

那在.htaccess里面能否设置一条规则
如果只是以http://www.xxx.com域名方式访问的话就跳转到http://www.xxx.com/index.html,
而已http://www.xxx.com/asdf或http://www.xxx.com/asdf/dfasd访问就访问index.php呢?

作者: ironcrane   发布时间: 2008-10-22

后来的规则要写在下面

作者: yz20sui   发布时间: 2008-10-23

规则怎么写?

作者: ironcrane   发布时间: 2008-10-23

RewriteRule ^(.*) http://www.xxx.com/index.php
RewriteRule http://www.xxx.com/$ http://www.xxx.com/index.html

不知道好不好用啊  对规则写法还不熟悉呢 :)

作者: yz20sui   发布时间: 2008-10-23

经验证,不起作用

作者: ironcrane   发布时间: 2008-10-23

找到解决办法了
RewriteEngine on
RewriteRule ^$ index.html
RewriteRule !\.(js|ico|gif|jpg|png|css|xml|htm|html|)$ index.php

作者: ironcrane   发布时间: 2008-10-23

热门下载

更多