【问题标题】:Mod_rewrite, trying to exclude images and css filesmod_rewrite,试图排除图像和css文件
【发布时间】:2014-07-19 06:49:49
【问题描述】:

我正在尝试找到一种方法从我的 mod_rewrite 权限中排除图像文件和 css 文件

Options +FollowSymLinks
RewriteEngine On

#SecFilterInheritance Off
ErrorDocument 404 /fourohfour.php

RewriteCond %{HTTP_HOST} ^(myurl\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !\.(?:css|png|jpe?g|gif)$ [NC,OR]  #my attempt at excluding

RewriteRule ^articles/([^/]+)/([^/]+)/?$ /article.php?id=$1&articleTopic=$2 [QSA,L]

问题在于排除线不太准确,我需要帮助

如果我转到我的目录中未包含在我的 .htaccess 重写中的任何 phpscript.. 说 isntance www.myurl.com/articlelinks.php 我会被重定向到这个:

http://www./articlelinks.php  

让事情更复杂:

如果我去: http://www.myurl.com/articles/1/Dorsal+and+Volar+Intercalated+Segment+Instability+(DISI+and+VISI) CSS 文件不加载

如果我去:

http://www.myurl.com/articles.php?id=1&articleTopic=Dorsal+and+Volar+Intercalated+Segment+Instability+(DISI+and+VISI) 正确的文档加载了 css 和图像

请帮忙?

【问题讨论】:

  • 使用正向模式。您的情况下的否定模式在逻辑上是错误的。

标签: php css apache .htaccess mod-rewrite


【解决方案1】:

你的条件中有一个OR 标志,但它之后没有其他条件,这让 mod_rewrite 认为:%{REQUEST_URI} !\.(?:css|png|jpe?g|gif)$ 或(任何东西)。尝试删除 OR

RewriteCond %{REQUEST_URI} !\.(?:css|png|jpe?g|gif)$ [NC]
RewriteRule ^articles/([^/]+)/([^/]+)/?$ /article.php?id=$1&articleTopic=$2 [QSA,L]

您的 CSS 未加载的原因可能是因为您在文档中使用了相对 URL 路径。尝试将这些链接更改为绝对 URL 路径(以 / 开头)或将其添加到页面标题:

<base href="/" />

空白主机问题,不知道为什么会这样。尝试添加这个条件:

RewriteCond %{HTTP_HOST} !^$

所以规则看起来像:

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^(myurl\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-04
    • 1970-01-01
    • 2012-07-22
    • 2015-09-28
    • 1970-01-01
    • 1970-01-01
    • 2012-07-05
    • 1970-01-01
    相关资源
    最近更新 更多