logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: How to redirect except specific url?
Author
Cui



Joined: 11 Jan 2016
Posts: 8
Location: Beijing

PostPosted: Wed 13 Jan '16 11:31    Post subject: How to redirect except specific url? Reply with quote

I want to redirect all urls from http to https except specific url.
Forexample:
http://domain.com => https://domain.com
http://domain.com/one => https://domain.com/one
http://domain.com/two => https://domain.com/two
http://domain.com/thr => http://domain.com/thr

So I write httpd.conf like this.
Code:

<VirtualHost *:80>
  DocumentRoot /var/www/html/
  ServerName domain.com
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteCond %{REQUEST_URI} ^(?!/thr) [NC]
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [LR]
</VirtualHost>


I load mod_rewrite.so.

What's wrong with this?
Thanks in advance.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Wed 13 Jan '16 13:15    Post subject: Reply with quote

Code:
<VirtualHost *:80>
  DocumentRoot /var/www/html/
  ServerName domain.com
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteCond %{REQUEST_URI} !=/thr
  RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
</VirtualHost>
Back to top
Cui



Joined: 11 Jan 2016
Posts: 8
Location: Beijing

PostPosted: Wed 13 Jan '16 15:05    Post subject: Reply with quote

Thanks for your reply.
If my url is longer than example, how can I do it?
Forexample:
http://domain.com/three/test?param=val
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Wed 13 Jan '16 17:44    Post subject: Reply with quote

Do a

RewriteCond %{REQUEST_URI} != ^/(three)
Back to top
Cui



Joined: 11 Jan 2016
Posts: 8
Location: Beijing

PostPosted: Thu 14 Jan '16 2:51    Post subject: Reply with quote

Thanks. It works well.
Back to top


Reply to topic   Topic: How to redirect except specific url? View previous topic :: View next topic
Post new topic   Forum Index -> Apache