Mod Rewrite规则将所有pdf请求重定向到另一个位置 [英] Mod Rewrite rule to redirect all pdf request to another location

查看:78
本文介绍了Mod Rewrite规则将所有pdf请求重定向到另一个位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试清理我们的网站.我正在使用ISAPI Rewrite.我已经弄清楚需要选择有问题的文件的正则表达式.

I'm trying to clean up our website. I'm using ISAPI Rewrite. I have figured out the regex I need to select the files in question.

^(?!.*?web_content.*?).*?\.pdf

我想重定向所有pdf请求以在web_content/pdf/中查找.所以我想要的伪规则是

I want to redirect all pdf requests to look in web_content/pdf/. So The pseudo rule I want is

将所有请求重定向到尚未请求的pdf web_content/pdf.删除原始文件夹路径. /somefolder/this/mycool.pdf ==>/web_content/pdf/mycool.pdf

redirect all requests to pdfs that aren't already being requested from web_content/pdf. Drop off the original folder path. /somefolder/this/mycool.pdf ==> /web_content/pdf/mycool.pdf

我的问题是我将如何实际创建Mod重写规则?我不知道如何正确执行替换命令.我也希望该规则不会影响我们网站上的外部pdf链接.

My question is how would I actually create the Mod rewrite rule? I don't know how to correctly do the replacement command. I also hope this rule wont affect external pdf links on our site.

推荐答案

这应该有效:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/web_content/pdf/
RewriteRule ^(.+\.pdf)$ /web_content/pdf/$1 [L]

Helicon ISAPI_Rewrite v3 与Apache的mod_rewrite几乎相同(除了一些高级功能),因此,几乎所有适用于Apache的规则在这里也都适用.

Helicon ISAPI_Rewrite v3 is pretty much the same as Apache's mod_rewrite (except few advanced things), therefore almost all rules that work on Apache will work here as well.

这篇关于Mod Rewrite规则将所有pdf请求重定向到另一个位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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