有没有办法通过.htaccess文件获取此信息?

时间:2013-04-01 09:56:38

标签: php apache mod-rewrite

在我的站点根目录中。有donghua.php和index.php。现在,有没有办法使用.htaccess文件让访问者访问我的网站。默认显示example.com/donghua.php。不是example.com/index.php。谢谢。服务器是Apache。

ps:用户仍然可以访问example.com/index.php

我在.htaccess中使用DirectoryIndex donghua.php。默认页面没问题。但是当我访问example.com/index.php时,它会重定向到example.com/donghua.php。如果我禁止它重定向我该怎么办?

3 个答案:

答案 0 :(得分:0)

如果您有权访问虚拟主机配置文件(或者您甚至可以在htaccess中执行此操作),可以根据需要将DirectoryIndex设置为donghua.php,即不是这样的:

DirectoryIndex index.html index.php default.html

只是做:

DirectoryIndex donghua.php

因此,每当有人访问您的网站example.com时,您的apache安装都会将donghua.php读作默认索引文件。

答案 1 :(得分:0)

在index.php的.htaccess文件中更改重定向规则。如果打开.htaccess文件,则可以找到以下行,

RewriteCond%{THE_REQUEST} ^。* / example.php

RewriteRule ^(。*)example.php $ http://www.test.com/ $ 1 [R = 301,L]

更改或删除index.php的此规则。最好删除或评论它,然后它不会重定向到另一个页面

“RewriteCond”此代码检查编码,如果浏览器请求文件名index.php。如果条件满足,则下一行将执行“RewriteRule”。此“RewriteRule”将重定向您的网址。

在.htaccess文件中搜索并找到名称“index.php”。评论出那条线。要评论的语法是“#”。

示例:

#RewriteCond

#RewriteRule

在更改.htaccess文件中的任何内容之前重新启动。

答案 2 :(得分:0)

使您的网址可爱且适合搜索引擎排名。

 Options +FollowSymLinks
 RewriteEngine on
 RewriteCond %{HTTP_HOST} ^yoursite.com
 RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
 RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.html HTTP/
 RewriteRule ^index.html$ http://www.yoursite.com/ [R=301,L]

重定向

redirect 301 /old-page.php http://www.yoursite.com/new-page.php
相关问题