Solved

htaccess redirect https:// to https://www

Posted on 2011-02-17
20
1,239 Views
Last Modified: 2012-05-11
Dear experts,

It is possible force redirect user that aceess to https:// (without www) to https://www in htaccess ?

Best regards

André Bolinhas
0
Comment
Question by:abolinhas
  • 10
  • 6
  • 4
20 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 34922709
If you have access to the DNS records for the web site, you do this by adding a CNAME DNS record:

www.yourdomain.com CNAME yourdomain.com

Open in new window

0
 
LVL 9

Author Comment

by:abolinhas
ID: 34924540
Hi sjklein42

I already have this record in my dns

Name	TTL	Class	Type	Record
www.fileplace.org.pt.	14400	IN	CNAME	fileplace.org.pt

Open in new window

0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34924718
you also need to define ServerAlias in the apache config
ServerAlias fileplace.org.pt 

Open in new window

0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 9

Author Comment

by:abolinhas
ID: 34925618
but this is not possible by htaccess ?

Why I need to put this
ServerAlias fileplace.org.pt
in apache
0
 
LVL 9

Expert Comment

by:jeremycrussell
ID: 34926744
Depending on if you are using NamedVirtualHost you may or may not need to use ServerAlias.

As for the redirect, yes, you can do that.

Try:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^fileplace.org.pt$
RewriteRule (*.) https://www.fileplace.org.pt/$1

in the .htaccess
0
 
LVL 9

Author Comment

by:abolinhas
ID: 34926800
I get a 500 internal error
0
 
LVL 9

Expert Comment

by:jeremycrussell
ID: 34926890
Make sure you're loading the mod_rewrite module in your apache httpd.conf file.

Here's a decent discussion on how to do that.  http://ubuntuforums.org/showthread.php?t=255556
0
 
LVL 9

Author Comment

by:abolinhas
ID: 34927001
I have the mod_rewrite enable.

This code work very well on my htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.fileplace.org.pt/

This code redirect all user that try access to site via http or www to https:/www

And now I want redirect user that try access to site via https to https://www
0
 
LVL 9

Author Comment

by:abolinhas
ID: 34939781
Hi experts

Any news about my problem ?

Best regards

André Bolinhas
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34939861
Wouldn't that be server port 443?

Add these two additional rewrite lines:

RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ https://www.fileplace.org.pt/

Open in new window

0
 
LVL 9

Author Comment

by:abolinhas
ID: 34941609
nop, I get a loop error.
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34941779
I am not clear on what your https redirect is supposed to do.  Is this right?
https://www.fileplace.org.pt/anything  is supposed to go to https://www.fileplace.org.pt/

Open in new window

If so, to avoid a loop you may need to do this for the https redirect (note the "+" instead of "*" matches only non-zero-length strings):

RewriteCond %{SERVER_PORT} 443
RewriteRule ^/(.+)$ https://www.fileplace.org.pt/ 

Open in new window

0
 
LVL 9

Author Comment

by:abolinhas
ID: 34941974
I am not clear on what your https redirect is supposed to do.  Is this right?
I want only this:
https://fileplace.org.pt -> https://www.fileplace.org.pt

Open in new window


This code don't work to :(
RewriteCond %{SERVER_PORT} 443
RewriteRule ^/(.+)$ https://www.fileplace.org.pt/

Open in new window

0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34942094
I must admit I am not such an expert on this but I found this reference.

http://httpd.apache.org/docs/1.3/misc/rewriteguide.html

Canonical Hostnames
Description:
The goal of this rule is to force the use of a particular hostname, in preference to other hostnames which may be used to reach the same site. For example, if you wish to force the use of www.example.com instead of example.com, you might use a variant of the following recipe.

Please try the following.  If I understand how it works correctly, it should handle both the http and https redirects.

RewriteCond %{HTTP_HOST}   !^www\.fileplace\.org\.pt [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         https://www.fileplace.org.pt/$1 [L,R]
 

Open in new window

0
 
LVL 9

Author Comment

by:abolinhas
ID: 35017688
I alredy try all schemas but not work.

Any more options ?

0
 
LVL 16

Expert Comment

by:sjklein42
ID: 35017769
I'm stuck.  Maybe try asking the question again to get some fresh attention.  No soup for me.  Sorry.
0
 
LVL 9

Expert Comment

by:jeremycrussell
ID: 35017839
This

https://fileplace.org.pt -> https://www.fileplace.org.pt

Open in new window


is probably not working as you would hope because you are getting a certificate error when hitting https://fileplace.org, correct?

Even if you redirect, the client has already requested the host fileplace.org on port 443, which has already sent the configured cert, and if you are using the same certificate for www.fileplace.org and that's the only common name for that cert, then your client will get the error, and will have to click through to get redirected.

0
 
LVL 9

Author Comment

by:abolinhas
ID: 35017880
Hi jeremycrussell,

Yes this is the reason that I need to make a redirect, with https://www.fileplace.org.pt, I don't get the certificate error.

So, I can not do this with htaccess ?

Best regards

André Bolinhas
0
 
LVL 9

Accepted Solution

by:
jeremycrussell earned 500 total points
ID: 35018092
No, unfortunately this is a problem with the cert.  You would have to provide a valid cert for fileplace.org to avoid the error when accessing https://fileplace.org.
0
 
LVL 9

Author Closing Comment

by:abolinhas
ID: 35081300
Thanks for help me to understand my probrlem.

Best regards

André Bolinhas
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

831 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