Mod Rewrite rule to redirect all pdf request to another location
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 alread开发者_Go百科y 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.
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.
精彩评论