2013-04-01 30 views
0

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

PS:example.com/index.php

我在.htaccess使用DirectoryIndex donghua.php用户仍然可以访问。默认页面没问题。但当我访问example.com/index.php它重定向到example.com/donghua.php。如果我禁止它重定向我该怎么办?

回答

0

如果你有权访问虚拟主机配置文件(或者你甚至应该可以在htaccess中做到这一点),你可以设置DirectoryIndex为donghua.php,如果你想,也就是说,而不是像这样:

DirectoryIndex index.html index.php default.html 

只要做到:

DirectoryIndex donghua.php 

所以每当有人去你的网站,example.com,Apache安装将读取donghua.php作为默认的索引文件。

+0

我厌倦了你的密码,默认的页面就可以了。但我仍然想访问http://www.example.com/index.php – linuxlearner

+0

当我访问example.com/index.php时,它总是重定向到example.com/donghua.php – linuxlearner

0

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

的RewriteCond%{} THE_REQUEST^* /使用example.php

重写规则^(。*)使用example.php $ http://www.test.com/ $ 1 [R = 301,L]

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

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

在.htaccess文件中搜索并找到名称“index.php”。注释掉这些行。要评论的语法是“#”。

例子:

#RewriteCond

#RewriteRule

在.htaccess文件进行任何更改之前拿回来了。

+0

我不知道如何要做什么?你能否更清楚地说清楚。谢谢 – linuxlearner

+0

“RewriteCond”这段代码检查编译器是否浏览器请求文件名index.php。如果条件满足,则下一行将执行“RewriteRule”。这个“RewriteRule”会重定向你的URL。 在.htaccess文件中搜索并找到名称“index.php”。注释掉这些行。要评论的语法是“#”。 示例: #重写密码 #重写规则 在更改.htaccess文件中的任何内容之前进行备份。 –

+0

RewriteCond%{THE_REQUEST} ^。*/index.php RewriteRule ^(。*)donghua.php $ http://www.test.com/$1 [R = 301,L]我把这段代码放入,但是它不起作用 – linuxlearner

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 
+0

iput你的代码,但它不工作 – linuxlearner

+0

请访问此链接 http://www.branded3.com/blogs/htaccess-mod_rewrite-终极指南/ –

+0

谢谢。根据我想,如何编写规则? – linuxlearner

相关问题