.htaccess - 没有请求的URI时

Rém*_*ton 3 .htaccess

我正在寻找一个.htaccess文件,让任何请求传递到其原始目标但重定向到特定文件夹(在这种情况下为启动画面)是没有指定目标.我不是很精通,.htaccess也会感激一些帮助.

示例:我正在请求http://www.domain.com/folder/file.php,它应该通过.但如果我要求http://www.domain.com/,它应该重定向到http://www.domain.com/splash/.

我至今正确地重定向到/splash/,但重定向一切/splash/.

<IfModule mod_rewrite.c>
    RewriteEngine On

    # If the requested URI is empty...
    RewriteCond %{REQUEST_URI} !^$

    # ...then redirect to the "splash" folder
    RewriteRule .* splash [L]

    # Otherwise rewrite the base
    RewriteBase /

    # If the request is not a folder or a file, redirects to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

谢谢!

编辑:重要的一点是将http://www.domain.com/重定向到http://www.domain.com/splash/,但允许直接访问http://www.domain.com/index. PHP.

Jon*_*Lin 7

%{REQUEST_URI}变量包含一个前导斜杠,因此它永远不会是空白.你可以摆脱它,只需使用这个规则:

RewriteRule ^/?$ /splash/ [L,R]
Run Code Online (Sandbox Code Playgroud)

如果您希望浏览器地址栏中显示的URL保留http://www.domain.com/,请,R从方括号中删除:[L].