阻止访问整个文件夹,而是路由到index.php

时间:2017-01-02 13:48:24

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

我正在尝试编写.htaccess重写规则,将所有流入domain.com/system/*的流量重定向回domain.com。

到目前为止我写过这个:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1/ [L]

但是如果我去的话,它没有按预期工作:

domain.com/system/inexistent_file 

它有效。但是,如果我去:

domain.com/system/existing_file.php 

它将打开指定的文件,而不是显示index.php的内容。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

试试这个:

Options +FollowSymLinks

<IfModule mod_rewrite.c>
    RewriteEngine on

    # Match against the host, if you wish
    #RewriteCond %{HTTP_HOST} ^domain\.com$

    RewriteRule system/(.*) /index.php?/$1 [L,R]
</IfModule>

适用于现有和不存在的文件。

[R] flag就在那里,因为您声明要重定向。

相关问题