Mod Rewrite rule to redirect all pdf request to an

2019-08-30 17:33发布

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

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

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

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.

1条回答
地球回转人心会变
2楼-- · 2019-08-30 17:54

This should work:

RewriteEngine On

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

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.

查看更多
登录 后发表回答