首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将网站重定向到特定文件?

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

Stack Overflow用户
提问于 2011-11-23 00:34:47
回答 4查看 122关注 0票数 0

有一个域名。假设是domain.com

当用户仅键入domain.com时,他应该被重定向到地址domain.com/file.html。如何使用.htaccess文件做到这一点?

另外,RewriteRule ^index\.php$ - [L]是什么意思?这对我有帮助吗?

EN

回答 4

Stack Overflow用户

发布于 2011-11-23 00:36:42

添加到.htaccess文件

代码语言:javascript
复制
DirectoryIndex file.html 
票数 0
EN

Stack Overflow用户

发布于 2011-11-23 00:41:40

查看这个站点:.htaccess tricks and tips,它是重写规则的一个很好的参考。

至于RewriteRule ^index.php$ -L是什么意思。它将忽略所有以index.php结尾Rewrite Rule meaning的内容

票数 0
EN

Stack Overflow用户

发布于 2011-11-23 00:48:07

要重定向,您可以创建一个索引页(用户访问的第一个页面)

代码语言:javascript
复制
DirectoryIndex file.html

根据此link修改您的.htaccess文件。

对于RewriteRule,您需要在apache中启用mod_rewrite模块,然后在.htaccess文件中生成

代码语言:javascript
复制
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule (.*) file.html [L]
</IfModule>

RewriteRule中,您可以使用正则表达式来标识url,并将用户重定向到您想要的文件(在本例中,您可以将所有链接重定向到file.html)。更多信息here

此外,在apache服务器的配置文件中,默认情况下可能会有以下配置:

代码语言:javascript
复制
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.php index.php4 index.php3 index.cgi index.pl index.html index.htm index.shtml index.phtml
</IfModule>

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8230256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档