我想知道如何使用.htaccess
规则将我的域指向index.php
我实际需要它做什么:
domain.com
时,会将他带到www.domain.com/index.php
和
domain.com/index.php
时,他需要www.domain.com/index.php
或当用户输入domain.com/file.php
时,他需要www.domain.com/file.php
我在stackoverflow上搜索了一些规则,但这些规则不完整,没有人能够执行这两个功能。
有一条规则:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^$ http://www.example.com/index.php [L,R=301]
当用户进入domain.com时,会将他带到www.domain.com/index.php,但它无法将输入domain.com/index.php的用户重定向到www.domain.com/index.php ..或者让我们说像domain.com/file.php这样的东西到www.domain.com/file.php
任何人都请帮忙解决这个问题。我相信很多用户都想知道这一点。 提前谢谢。
答案 0 :(得分:1)
在我的.htaccess文件中,我有
##
# Rewrite http://domain.com to http://www.domain.com (for XYZ licence)
##
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
答案 1 :(得分:0)
上的RewriteEngine
RewriteCond %{HTTP_HOST} !^www.domain.com
RewriteCond %{HTTP_HOST} !^domain.com
RewriteRule ^$ /index.php [QSA,L]
RewriteRule ^file.php /file.php [L]