【问题标题】:Why RewriteCond is not working in httd.conf?为什么 RewriteCond 在 httpd.conf 中不起作用?
【发布时间】:2015-01-15 02:58:14
【问题描述】:

我有一个使用 Yii2 Web 框架的网站,我想用 apache 做的是在请求不要求 js 或 css 文件时重写 url。这是我的配置:

    #in httpd.conf
   <VirtualHost *:80> 
        DocumentRoot /Users/shenshijun/Sites/intuplus/frontend/web
        ServerName intuplus
        RewriteEngine On
        <IfModule rewrite_module>

            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^/(.*)$ /index.php/$1

            LogLevel alert rewrite:trace3
        </IfModule>
    </VirtualHost>

js文件的url如下:http://intuplus/assets/85c70b6b/js/bootstrap.js,去掉重写规则后就可以访问了。但是当我添加 rewriterule 和 rewritecond 时,url 无论如何都会被重写,我无法访问 js 文件或 css 文件。那么,有人能解释一下为什么 RewriteCond 在这里不起作用吗?

哦,apache版本:Server version: Apache/2.4.10 (Unix)

【问题讨论】:

    标签: apache mod-rewrite yii2


    【解决方案1】:

    你的重写规则是错误的,你应该试试这个:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php
    

    阅读更多:http://www.yiiframework.com/doc-2.0/guide-start-installation.html#recommended-apache-configuration

    【讨论】:

    • 我用的是正则表达式,你能解释一下为什么它不起作用吗?
    猜你喜欢
    • 2013-05-10
    • 1970-01-01
    • 2013-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多