有一个域名。假设是domain.com。
当用户仅键入domain.com时,他应该被重定向到地址domain.com/file.html。如何使用.htaccess文件做到这一点?
另外,RewriteRule ^index\.php$ - [L]是什么意思?这对我有帮助吗?
发布于 2011-11-23 00:36:42
添加到.htaccess文件
DirectoryIndex file.html 发布于 2011-11-23 00:41:40
查看这个站点:.htaccess tricks and tips,它是重写规则的一个很好的参考。
至于RewriteRule ^index.php$ -L是什么意思。它将忽略所有以index.php结尾Rewrite Rule meaning的内容
发布于 2011-11-23 00:48:07
要重定向,您可以创建一个索引页(用户访问的第一个页面)
DirectoryIndex file.html根据此link修改您的.htaccess文件。
对于RewriteRule,您需要在apache中启用mod_rewrite模块,然后在.htaccess文件中生成
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule (.*) file.html [L]
</IfModule>在RewriteRule中,您可以使用正则表达式来标识url,并将用户重定向到您想要的文件(在本例中,您可以将所有链接重定向到file.html)。更多信息here。
此外,在apache服务器的配置文件中,默认情况下可能会有以下配置:
#
# 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的文件,则总是首先调用该文件。
https://stackoverflow.com/questions/8230256
复制相似问题