htaccess的 - 当没有请求的URI [英] .htaccess - When there is no requested URI

查看:118
本文介绍了htaccess的 - 当没有请求的URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望做可以让任何请求传递到其原来的目的地,但重定向到一个特定的文件夹(在这种情况下,闪屏)一的.htaccess 文件没有指定的目的地。我不是很精通与的.htaccess 键,将AP preciate一些帮助。

I'm looking to do a .htaccess file that let any requests pass to its original destination but redirects to a specific folder (a splash screen in this case) is no destination is specified. I'm not very well-versed with .htaccess and would appreciate some help.

例:我请求 http://www.domain.com/folder/file。 PHP ,它应该通过。但是如果我请求 http://www.domain.com/ ,它应该重定向到的 http://www.domain.com/splash/

Example: I'm requesting http://www.domain.com/folder/file.php, it should go through. But if I'm requesting http://www.domain.com/, it should redirect to http://www.domain.com/splash/.

我至今正确地重定向到 /飞溅/ ,但重定向的所有 /飞溅/

What I have so far redirects correctly to /splash/, but redirects everything to /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>

谢谢!

编辑:很重要的一点是将重定向 http://www.domain.com/ 以< A HREF =htt​​p://www.domain.com/splash/相对=nofollow> http://www.domain.com/splash/ ,但允许直接访问的 http://www.domain.com/index.php

One important point would be to redirect http://www.domain.com/ to http://www.domain.com/splash/, but allow direct access to http://www.domain.com/index.php.

推荐答案

%{REQUEST_URI} 变量包含一个斜线,所以它永远不会是空白。你可以摆脱这一点,只需使用这条规则:

The %{REQUEST_URI} variable includes a leading slash, so it will NEVER be blank. You can get rid of that and just use this rule:

RewriteRule ^/?$ /splash/ [L,R]

如果你想显示在浏览器的地址栏中留下 http://www.domain.com/ 的URL,然后删除 ,R 从方括号: [L]

If you want the URL that appears in the browser's address bar to stay http://www.domain.com/, then remove the ,R from the square brackets: [L].

这篇关于htaccess的 - 当没有请求的URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆