【问题标题】:Apache Rewrite Exclusion on CSS FileCSS文件上的Apache重写排除
【发布时间】:2012-05-13 02:15:29
【问题描述】:

一个慈善机构要求我帮助他们开发他们的新网站,这是一个使用 Expression Engine 的 PHP 网站。

他们要求我摆脱 .php 扩展名,并将博客的表达式引擎路径从 /index.php/blog 重写为 /blog。我已经通过下面的重写做到了这一点,但是没有显示博客的 CSS 文件,必须在重写中赶上。

如何排除?

mysite.org/?css=Home/site_styles.v.1335444432

从重写?

非常感谢。

DirectoryIndex home.php
Options Indexes Includes FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\s.+\.php [NC]
RewriteRule ^(.+)\.php$ /$1 [NE,R=301,L,NC]
RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)/?$ /$1.php [L]

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

【问题讨论】:

    标签: apache codeigniter mod-rewrite rewrite expressionengine


    【解决方案1】:

    将此放在所有其他规则之前

    RewriteRule ^(site_styles)($|/) - [L]
    

    如果你想排除多个东西:

    RewriteRule ^(site_styles|js|css|images)($|/) - [L]
    

    【讨论】:

    • 非常感谢您的帮助。那些在这种情况下不起作用。我可以看到问题。 /index.php?css=Home/site_styles.v.1335444432 正在重写为 /css=Home/site_styles.v.1335444432。所以我需要一种单独排除或重写的方法。
    【解决方案2】:

    您可能还想检查是否使用绝对路径而不是相对路径调用 CSS,因为您可能刚刚破坏了与重写的相对链接?

    【讨论】:

    • 我明白了,谢谢,上面的解决方案确实有效。我有一个主机文件指向我忘记的旧服务器。谢谢大家。
    猜你喜欢
    • 2012-03-10
    • 2011-10-24
    • 1970-01-01
    • 1970-01-01
    • 2018-07-12
    • 1970-01-01
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多