.htaccess从站点的根目录重定向到index.php

时间:2017-01-17 09:48:21

标签: php .htaccess

问题是我需要被重定向到projects.test.net/rr/index.php如果我来到网站的根目录http://projects.test.net/rr/

为什么第一次重写规则不起作用?我也尝试过添加

RewriteCond %{HTTP_HOST}^projects.pepperit.net/rr/ [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

但它不起作用。整个文件在这里:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST}^projects.test.net/rr/$ [NC]
RewriteRule ^(.*)$http://projects.test.net/rr/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

2 个答案:

答案 0 :(得分:2)

添加DirectoryIndex修复了问题。

Options +FollowSymLinks
RewriteEngine on
DirectoryIndex index.php

RewriteCond %{HTTP_HOST}^projects.test.net/rr/$ [NC]
RewriteRule ^(.*)$http://projects.test.net/rr/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

答案 1 :(得分:2)

服务器中的常用设置可能很多,但您想使用可以使用DirectoryIndex设置的index.php

Options +FollowSymLinks
RewriteEngine on
DirectoryIndex index.php

RewriteCond %{HTTP_HOST}^projects.test.net/rr/$ [NC]
RewriteRule ^(.*)$http://projects.test.net/rr/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]