I want to use Apache's mod_rewrite
to redirect all URLs that does not end with /feed
to a secure URL (identical, but starting with https
), and leave all that ends with /feed
unaltered:
I want this:
http://example.com/node/1234 => https://example.com/node/1234
http://example.com/blog/feed => http://example.com/blog/feed
Then I added the following rules:
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule !^/?(.*)/feed$ https://%{SERVER_NAME}/$1 [R,L]
What happens is this:
http://example.com/node/1234 => https://example.com/node/1234
http://example.com/blog/feed => https://example.com
The first one is the expected result, the second is not. Comment by w3d explains why this one doesn't work.
I have also tried (based on Martijn's answer):
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !/feed$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
While I can't get this to work, I now think the problem is located elsewere and that this is the correct way to write this rule.
!^/?(.*)/feed$
- you cannot have a capturing subpattern in a negated regex in mod_rewrite.$1
will always be empty.