Solved

ssl redirection is not working- mod_rewrite...........

Posted on 2010-08-28
11
393 Views
Last Modified: 2012-05-10
Hi,

I want to redirect https://xyz.com to https://www.xyz.com, but somehow its not working.
we are using mod_rewrite module with apache.

Could you please direct us how to do it..........


Also its seems to be some ssl header limitation. Could you demonstrate the data flow difference between https and http



Regards.
0
Comment
Question by:pradeep_bansal
  • 7
  • 3
11 Comments
 
LVL 7

Expert Comment

by:mcuk_storm
ID: 33548878
An example of how to achieve this would be:

        RewriteEngine on
        RewriteCond %{SSL} !^off$
        RewriteRule ^(.*)$      https://%{HTTP_HOST}$1
0
 

Author Comment

by:pradeep_bansal
ID: 33548938
Its working fine with http to https......
but its not working with https to https redirection......


I have done everything similar to above reply but didnt yeild anything positive.
0
 
LVL 7

Expert Comment

by:mcuk_storm
ID: 33548963
The rewrite rule for the xyz.com to www.xyz.com would be something like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$      https://www.%{HTTP_HOST}$1 [L]

It does work ( i have tested it on a live setup ) but please ensure that these rewrite rules are in the site configuration for the SSL site not the site running on port 80.
0
 

Author Comment

by:pradeep_bansal
ID: 33548980
Well we are using more than one ports in apache server.


Is there any way from which this rule only confines upto 443 port.(i.e can we use AND loop in RewriteCondition--- (443)&&(!^www\.))



Please suggest..........
0
 
LVL 7

Expert Comment

by:mcuk_storm
ID: 33549069
You can add another RewriteCond so
RewriteEngine on
RewriteCond %{HTTPS} !^off$
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$      https://www.%{HTTP_HOST}$1 [L]

This will redirect to the www. version if they are using https and aren't going to the www. version.

I think i may have just worked out what you are trying to achieve, if your certificate isn't valid for the non www. version they will still get the warning message and have to accept it before this redirect will work to direct the to the domain for which the cert if valid.
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 

Author Comment

by:pradeep_bansal
ID: 33565175
This is also giving me same result:        NO REDIRECTION


It works fine for url with http but not with https.................
0
 

Author Comment

by:pradeep_bansal
ID: 33575986
When the https header request flows then firstly it forward to CA url............ so if CA find exact url then simply throws error of bad certificate...................so rewrite process which should be taken place after ssl authentication remain unhit..........
0
 

Author Comment

by:pradeep_bansal
ID: 33576416
And after accepting "This Connection is Untrusted" message, the redirection rule is working perfectly.



But I require this before all that.........................
0
 

Author Comment

by:pradeep_bansal
ID: 33585215
Just clearing my post:


we have bought certificate for https://www.xyz.com and not for https://xyz.com.


So, we want https://xyz.com request to redirect  on https://www.xyz.com..............
but on hitting https://xyz.com, apache takes us to the message(ssl untrusted). which we want to bypass..
0
 
LVL 15

Expert Comment

by:samri
ID: 33585319
Hi pradeep,

I am not sure if this is possible at all.  Apologies for my naiveness.

If we were to look at the situation, client type in https://xyz.com/ and hit your apache, then during ssl handshake, the Browser (and not Apache) that is complaining about the certificate name mistmatch.  Note that the certificate common name is www.xyz.com, but the request is going to xyz.com.

excellent info here:
http://publib.boulder.ibm.com/infocenter/tivihelp/v2r1/index.jsp?topic=/com.ibm.itame2.doc_5.1/ss7aumst18.htm

just my 1 cents.
0
 

Accepted Solution

by:
pradeep_bansal earned 0 total points
ID: 33680953
Yes this can not be acheived as the ssl request firstly goes to CA site.
The only way is to use wild card certificate for whole domain.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now