繁体   English   中英

如何使默认页面home.php代替index.html和index.php

[英]how to make default page home.php instead of index.html and index.php

我有网站http://mywebsite.com。如果我点击此URL,则将index.php和index.html作为默认页面。 如何将home.php设置为默认页面。 我已经尝试过,但是无法通过将以下代码放在public_html的.htaccess文件中来工作

DirectoryIndex home.php index.html index.php

您只需要在DirectoryIndex中使用home.php即可使其工作。 请记住,这是在您的根项目的.htaccess文件中使用的:

DirectoryIndex home.php

您需要httpd.conf AllowOverride +Indexes才能使用.htaccess DirectoryIndex

除非如此,绝对最简单的重定向方法(无需root访问Apache配置和模块)就是将其作为index.html

<!doctype html>
<html>
  <head>
    <meta http-equiv="Refresh" content="0; url=home.php">
  </head>
  <body>
  </body>
</html>

DirectoryIndex指令适用于所有子文件夹,如果要为每个目录设置不同的文件,则可以使用mod-rewrite。

要将/file.html设置为根目录处理程序,可以在htaccess的顶部使用它:

RewriteEngine on
RewriteRule ^$ /file.html [L]

要将不同文件设置为子文件夹的索引,请使用以下命令:

RewriteEngine on
RewriteRule ^subfolder/$ /myfile.html [L]

只需尝试将/index.html/index.php重写为/home.php

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_URI} ^/index\.(html|php)
RewriteRule ^(.*) /home.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM