Php 如何将网站重定向到特定文件?

Php 如何将网站重定向到特定文件?,php,.htaccess,Php,.htaccess,有一个域名。比如domain.com 当用户仅键入domain.com时,应将其重定向到domain.com/file.html地址。如何使用.htaccess文件执行此操作 另外,重写规则^index\.php$-[L]意味着什么?它能帮我吗?添加到您的.htaccess文件中 DirectoryIndex file.html 看看这个网站:这是一个很好的参考重写规则 至于RewriteRule^index.php$-[L]是什么意思。它将忽略index.php结尾的任何内容以重定向。您可

有一个域名。比如domain.com

当用户仅键入domain.com时,应将其重定向到domain.com/file.html地址。如何使用.htaccess文件执行此操作


另外,重写规则^index\.php$-[L]意味着什么?它能帮我吗?

添加到您的.htaccess文件中

DirectoryIndex file.html 
看看这个网站:这是一个很好的参考重写规则


至于RewriteRule^index.php$-[L]是什么意思。它将忽略index.php结尾的任何内容以重定向。您可以将索引页作为用户访问的第一页

DirectoryIndex file.html
根据此修改.htaccess文件

对于RewriteRule,您需要在apache中启用该模块,然后在.htaccess文件中进行修改

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule (.*) file.html [L]
</IfModule>

因此,默认情况下,如果您在domain.com的webroot中有一个名为index.php的文件,则始终会首先调用该文件。

尝试将以下内容放入位于domain.com根目录中的.htaccess文件中

RewriteEngine On
RewriteBase /

#put all the following rules before any other rules in the .htaccess file
RewriteRule ^file\.html$ - [L]

#domain.com or any subdomain 
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$ [NC]
#the root of domain   
RewriteCond %{REQUEST_URI} ^/?$ [NC]
#return file.html
RewriteRule . file.html [L]

那index.php文件呢?如果我写index.php文件,它会重定向到文件.html@Álvaro G.Vicario:是的,我试过了,它可以工作。也许是主机的问题?因为它总是重定向到domain.com,当你添加index.php时,即使没有DirectoryIndex。我写了DirectoryIndex file.html,但当index.php是时,它也重定向到file.htmlis,这是你的.htaccess文件中唯一的条目RewriteRule^index.php$-[L]?即使我删除了所有htaccess代码,它仍然重定向到domain.com,当您键入domain.com/index.php时,index.php文件中没有重定向它的内容。您有权访问主机吗?web服务器上可能有重定向设置。服务器上是否有httpd.conf文件或正在使用其他重写方法。
RewriteEngine On
RewriteBase /

#put all the following rules before any other rules in the .htaccess file
RewriteRule ^file\.html$ - [L]

#domain.com or any subdomain 
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$ [NC]
#the root of domain   
RewriteCond %{REQUEST_URI} ^/?$ [NC]
#return file.html
RewriteRule . file.html [L]