php - Mod_rewrite,试图排除图像和 css 文件

标签 php css apache .htaccess mod-rewrite

我正试图找到一种从我的 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 和图像

请帮忙?

最佳答案

你的条件中有一个 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]

关于php - Mod_rewrite,试图排除图像和 css 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23938859/

相关文章:

java - Java 和 PHP 中的 DES 加密

jquery - 调整元素大小以避免重叠

apache - 无法在 HTTPD.CONF 文件中配置 mod_JK 以实现负载平衡

php - 当我点击链接时 mod_rewrite 页面名称两次

ruby-on-rails - 乘客从除根 url 之外的所有 url 开始

php - 前端 Controller 插件中的 Zend Framework 重定向导致重定向循环

php - PHP中的自动图像格式检测

javascript - 如果我选择索引值大于当前颜色索引的颜色,则只能覆盖通过 mousedown 应用的颜色

php - 等价于纯 PHP 中的 $request->path()

html - 为什么内容显示在这个 DIV 之外?