LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 02-07-2014, 02:41 AM   #1
tquang
Member
 
Registered: Jul 2010
Posts: 43

Rep: Reputation: 0
Apache and problem with redirect between HTTP and HTTPS


Dear everyone,

I installed Apache 2.2.4 and I have problem with redirect. Please help me and below my config (also what I need to run for my site)

My Apache had configurated with SSL and auto redirect from non SSL to SSL (HTTP > HTTPS)
Code:
<VirtualHost *:80>
        ServerName ABC.COM
        ServerAlias www.ABC.COM
        <Location />
                Redirect permanent / https://ABC.COM/
        </Location>
</VirtualHost>

<VirtualHost *:443>
        ServerName ABC.COM
        ServerAlias www.ABC.COM
        DocumentRoot /home/ABC/www/ABC.COM
        <Directory /home/ABC/www/ABC.COM>
             DirectoryIndex index.html index.php
             Order allow,deny
             Allow from all
        </Directory>
        SSLEngine on
        SSLCertificateFile /usr/local/apache/conf/ssl.crt
        SSLCertificateKeyFile /usr/local/apache/conf/ssl.key
        SSLCertificateChainFile /usr/local/apache/conf/ssl.crt
</VirtualHost>
So, above the config is good and no problem until in this site had link like as: ABC.COM/TEST (ABC.COM/TEST/view?code=12)
At this link, I want to redirect it from HTTPS to HTTP for this link only, but I don't know way to do.

Default is HTTPS for all, but ABC.COM/TEST (also ABC.COM/TEST/view?code=12) is HTTP only

Please help me. Thank so much

Last edited by tquang; 02-07-2014 at 02:54 AM.
 
Old 02-07-2014, 03:03 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6
Posts: 1,398

Rep: Reputation: 433Reputation: 433Reputation: 433Reputation: 433Reputation: 433
I use this format:

Code:
<VirtualHost xxx.xxx.xxx.xxx:80>
  ServerName www.mydomain.com
  ServerAlias mydomain.com
  RedirectMatch 301 (.*) https://www.mydomain.com$1
</VirtualHost>
 
Old 02-07-2014, 03:08 AM   #3
tquang
Member
 
Registered: Jul 2010
Posts: 43

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by TenTenths View Post
I use this format:

Code:
<VirtualHost xxx.xxx.xxx.xxx:80>
  ServerName www.mydomain.com
  ServerAlias mydomain.com
  RedirectMatch 301 (.*) https://www.mydomain.com$1
</VirtualHost>
Thank you, Sir. But I need to redirect 1 sub-link (subfolder, ...) from https (ssl) to http (non ssl). In your config is redirect from non ssl to ssl
 
Old 02-07-2014, 03:23 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6
Posts: 1,398

Rep: Reputation: 433Reputation: 433Reputation: 433Reputation: 433Reputation: 433
Ah, my mistake, I've not had my first coffee today
 
Old 02-07-2014, 03:42 AM   #5
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,884

Rep: Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322
@OP
Remove the redirect and use mod_rewrite:
Code:
RewriteEngine On

RewriteCond %{REQUEST_URI} !^/TEST
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
 
Old 02-07-2014, 03:51 AM   #6
tquang
Member
 
Registered: Jul 2010
Posts: 43

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bathory View Post
@OP
Remove the redirect and use mod_rewrite:
Code:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/TEST
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Sorry, I don't understand because as I known your rewrite code will made from URL-NoSSL to URL-SSL (if so, not right as my case), please check it!

Last edited by tquang; 02-07-2014 at 03:57 AM.
 
Old 02-07-2014, 04:09 AM   #7
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,884

Rep: Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322
Quote:
Sorry, I don't understand because as I known your rewrite code will made from URL-NoSSL to URL-SSL (if so, not right as my case), please check it!
What you mean by that?
The above code will rewrite all http requests to https except from /TEST(.*). Isn't that what you want to do?
 
Old 02-07-2014, 04:12 AM   #8
tquang
Member
 
Registered: Jul 2010
Posts: 43

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bathory View Post
What you mean by that?
The above code will rewrite all http requests to https except from /TEST(.*). Isn't that what you want to do?
Ah, sorry, I understood, thank you, Sir
 
Old 02-07-2014, 04:26 AM   #9
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,884

Rep: Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322
Quote:
Originally Posted by tquang View Post
Ah, sorry, I understood, thank you, Sir
If you want to rule out the possibility that someone uses https://ABC.COM/TEST..., you can add in the SSL virtualhost configuration, the following:
Code:
RewriteEngine On

RewriteCond %{REQUEST_URI} ^/TEST
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
Regards
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirect https to http on what zhjim Linux - Software 2 07-19-2013 04:28 PM
Redirect HTTP to HTTPS: bates Linux - Server 4 10-01-2010 11:10 AM
redirect http to https nagavinodh Linux - Newbie 3 09-24-2009 08:34 AM
How to redirect http to https? Sovan Linux - Server 1 12-03-2008 01:11 PM
redirect http to https awreneau Linux - Server 17 10-14-2008 09:13 AM


All times are GMT -5. The time now is 05:22 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration