: How to redirect all that URLs that does not end with "feed" to https? I want to use Apache's mod_rewrite to redirect all URLs that does not end with /feed to a secure URL (identical, but
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:
example.com/node/1234 => example.com/node/1234 example.com/blog/feed => example.com/blog/feed
Then I added the following rules:
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule !^/?(.*)/feed$ %{SERVER_NAME}/ [R,L]
What happens is this:
example.com/node/1234 => example.com/node/1234 example.com/blog/feed => 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 ^(.*)$ %{HTTP_HOST}/ [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.
More posts by @Caterina187
2 Comments
Sorted by latest first Latest Oldest Best
An alternative to Martijn's answer, except using a negative-lookbehind in the RewriteRule pattern without using an additional condition:
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)(?<!/feed)$ example.com/ [R,L]
Matches all URLs that do not end with /feed.
You can use $ which means "Ends"
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !/feed$
# "Ends with /feed" ------------^
RewriteRule ^(.*)$ www.%{HTTP_HOST}/ [R=301,L]
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.