Mobile app version of vmapp.org
Login or Join
Caterina187

: 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

@Caterina187

Posted in: #Apache #ModRewrite

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.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Caterina187

2 Comments

Sorted by latest first Latest Oldest Best

 

@Alves908

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.

10% popularity Vote Up Vote Down


 

@Chiappetta492

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]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme