为什么我的重写规则只适用于特定的单词?

时间:2015-04-02 19:33:12

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

我需要一个重写规则,它会将每个请求重写为index.php,除非单词web在网址中。因此,每个图像,JS,CSS文件都位于Web文件夹下。这是我的.htaccess文件,目前可以解决这个问题:

<IfModule mod_rewrite.c>
    RewriteEngine On
    # Folders / files to exclude from rewrite divided by Pipe goes here:
    RewriteRule (^|/)web(/|$) - [L,NC]

    # turn empty requests into requests for "index.php",
    # keeping the query string intact
    RewriteRule ^$ index.php [QSA]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !favicon.ico$
    RewriteRule ^(.+)$ index.php [QSA,L]

    RewriteRule ^(.+)$ index.php [QSA,L]
</IfModule>

这适用于:

http://localhost/~alpham8/application/index/index/
http://localhost/~alpham8/application/
http://localhost/~alpham8/application/index/someaction/
http://localhost/~alpham8/application/web/img/someimage.png

但它不起作用:

http://localhost/~alpham8/application/somecontroller/someaction/

无效URL会返回404错误。

请帮帮我。

0 个答案:

没有答案