从mod_rewrite规则中排除图像 [英] Excluding images from mod_rewrite rule

查看:62
本文介绍了从mod_rewrite规则中排除图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的htaccess脚本无意中更改了图像URL,因此URL路径中带有"portfolio/"的任何图像都会受到不利影响.

Inadvertently my htaccess script is changing image URLs so that any image with "portfolio/" in its URL path is adversely affected.

有什么方法可以将图像排除在该特定规则之外?

Is there any way to exclude images from that particular rule?

redirect 301 "/sitemap.xml" http://www.example.com/sitemap.php

RewriteEngine On

RewriteCond %{REQUEST_URI} !portfolio/project
RewriteCond %{REQUEST_URI} /.*portfolio/.*$ [NC]
RewriteRule ^(.*)portfolio(.*)$ /$1portfolio/project$2 [R=301,L]

RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/sitemap.php
RewriteRule ^(.*)$ /index.php/$1 [L]

推荐答案

对于第一部分(第一个重写规则),请尝试

For first part (first rewrite rule) try

RewriteCond %{REQUEST_URI} !portfolio/project
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_URI} /.*portfolio/.*$ [NC]
RewriteRule ^(.*)portfolio(.*)$ /$1portfolio/project$2 [R=301,L]

我不确定您为什么在第二个重写器中使用RewriteCond $1 !\.(gif|jpe?g|png)$ [NC].

I'm not sure why you use RewriteCond $1 !\.(gif|jpe?g|png)$ [NC] in second rewriterule.

RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png)$ [NC]表示您不想将以某些允许的图像扩展名结尾的URL的投资组合更改为投资组合/项目. [NC](不区分大小写)也用于跳过JPG,GIF,PnG等扩展名

RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png)$ [NC] means you don't want to change portfolio to portfolio/project for urls ending with some of allowed image extension. [NC] (case-insensitive) is used to skip JPG, GIF, PnG, etc extensions also

这篇关于从mod_rewrite规则中排除图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆