RewriteRule Works With "Match Everything" Pattern But Not Directory Pattern
Posted
by
kgrote
on Server Fault
See other posts from Server Fault
or by kgrote
Published on 2014-08-18T18:09:44Z
Indexed on
2014/08/18
22:23 UTC
Read the original article
Hit count: 268
mod-rewrite
|rewrite
I'm trying to redirect newsletter URLs from my local server to an Amazon S3 bucket.
So I want to redirect from:
https://mysite.com/assets/img/newsletter/Jan12_Newsletter.html
to:
https://s3.amazonaws.com/mybucket/newsletters/legacy/Jan12_Newsletter.html
Here's the first part of my rule:
RewriteEngine On
RewriteBase /
# Is it in the newsletters directory
RewriteCond %{REQUEST_URI} ^(/assets/img/newsletter/)(.+) [NC]
# Is not a 2008-2011 newsletter
RewriteCond %{REQUEST_URI} !(.+)(11|10|09|08)_Newsletter.html$ [NC]
## -> RewriteRule to S3 Here <- ##
If I use this RewriteRule
to point to the new subdirectory on S3 it will NOT redirect:
RewriteRule ^(/assets/img/newsletter/)(.+) https://s3.amazonaws.com/mybucket/newsletters/legacy/$2 [R=301,L]
However if I use a blanket expression to capture the entire file path it WILL redirect:
RewriteRule ^(.*)$ https://s3.amazonaws.com/mybucket/newsletters/legacy/$1 [R=301,L]
Why does it only work with a "match everything" expression but not a more specific expression?
© Server Fault or respective owner