我使用。htaccess文件将所有请求重定向到子文件夹中的index.php文件。
文件夹和文件结构:
/var/www/html/.htaccess
/var/www/html/my-folder/index.php
主html文件夹中只有。htaccess文件和my-folder目录。
我的。htaccess文件内容为:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /my-folder/index.php [L]
所有请求实际上都被重定向到正确的位置,即my-folder中的index.php文件。所有请求都要求url只是主机名。例如:
www.my-host.com/path -> Redirects correctly
www.my-host.com/path/ -> Redirects correctly
www.my-host.com/path/another-path -> Redirects correctly
www.my-host.com/file.php -> Redirects correctly
www.my-host.com -> Won't redirect
www.my-host.com/ -> Won't redirect
我做错了什么?
模式中的.
意味着URI中必须有一些东西,尝试使其成为可选的或使用^
代替:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /my-folder/index.php [L]