htaccess重定向如果不以文件夹开头

时间:2016-06-09 09:04:06

标签: php .htaccess mod-rewrite url-rewriting

我想创建一个白名单文件夹,并将所有其他请求重定向到索引

url.com/public/.* <-- Can access to file on public folder
url.com/xxxx <-- redirect to index.php

我使用此.htaccess (但它不适用于1and1'500错误')

<IfModule mod_rewrite.c>

    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    RewriteRule !^public/.* index.php [L,NC]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

</IfModule>

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

尝试:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule !^public /index.php [L]