Solved

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

Posted on 2011-02-17
20
1,211 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
Comment Utility
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
Comment Utility
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
Comment Utility
you also need to define ServerAlias in the apache config
ServerAlias fileplace.org.pt 

Open in new window

0
 
LVL 9

Author Comment

by:abolinhas
Comment Utility
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
Comment Utility
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
Comment Utility
I get a 500 internal error
0
 
LVL 9

Expert Comment

by:jeremycrussell
Comment Utility
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
Comment Utility
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
Comment Utility
Hi experts

Any news about my problem ?

Best regards

André Bolinhas
0
 
LVL 16

Expert Comment

by:sjklein42
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 9

Author Comment

by:abolinhas
Comment Utility
nop, I get a loop error.
0
 
LVL 16

Expert Comment

by:sjklein42
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I alredy try all schemas but not work.

Any more options ?

0
 
LVL 16

Expert Comment

by:sjklein42
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for help me to understand my probrlem.

Best regards

André Bolinhas
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
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 demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

10 Experts available now in Live!

Get 1:1 Help Now