Solved

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

Posted on 2011-02-17
20
1,250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Suggested Courses

732 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