在htacess中如何在用户输入域名时重写规则?

时间:2015-05-26 18:58:17

标签: .htaccess

我的.htaccess文件中有以下内容:

#when the user types the domain name only
RewriteCond %{REQUEST_FILENAME} ^$
RewriteRule . /index2.php [L]

我的目标是在用户仅在浏览器地址栏中键入doman名称时运行index2.php。但是,该代码似乎不起作用。

我也尝试过其他变化而没有成功:

#when the user types the domain name only
RewriteCond ! %{REQUEST_FILENAME}
RewriteRule . /index2.php [L]

 RewriteRule ^/$ /index2.php [L]

1 个答案:

答案 0 :(得分:1)

您不需要重写规则。只需在根目录中使用此行.htaccess:

DirectoryIndex index.php