Forum Moderators: phranque

Message Too Old, No Replies

Using mod rewrite to direct https to secure domain

Trying to redirect https requests to a domain that uses a shared SSL certif

         

KenS

12:02 pm on Jun 24, 2015 (gmt 0)

10+ Year Member



My standard URL is of the form http://www.example.com. The hosting package I'm using includes a shared SSL certificate. To use the shared SSL certificate it is necessary to use the URL https://hosting_domain/www.example.com. I have been trying to use mod_rewrite to rewrite all https requests to use the URL that will make use of the shared SSL certificate, but with no success. I only want to rewrite https requests, not http requests.

mod_rewrite is enabled on my shared server, and I have my own .htaccess file, which is where I have been attempting to create the necessary rewrite rules.

My only knowledge of mod rewrite is what I have read over the last few days. It have seen lots of examples on the web, but these are mainly to redirect all http requests to https. What I want to do is leave http requests as is, and only redirect https requests to the url that is prfixed hosting_domain as above.

A common example I see is the following, and I have attempted to do something based on this, but with no success.

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}


I have also seen examples that test the port number, and then have rules based on that.

I'm sure it is an easy thing to do for an expert, but but I'm out of my comfort zone here, so any assistance gratefully received.

lucy24

4:57 pm on Jun 24, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



https://hosting_domain/www.example.com

Do you mean that that's the actual URL that users have to be redirected to? If so, this isn't a pure mod_rewrite issue; there's aliasing involved too. What physical directory does this new URL correspond to? Is it even in your own userspace?

KenS

6:49 am on Jun 25, 2015 (gmt 0)

10+ Year Member



Thank you for your reply.

Maybe I have caused confusion by not writing the full domain. The actual URL that needs redirecting to has a .net on the end, so is https://hosting_domain[dot net]/www.example.com. That is, "hosting_domain" was supposed to indicate a domain with dot extension - it is actually the domain of the company that hosts my site. I didn't write the .net on the end in the original post as I read you are not supposed to post URLs other than www.example.com.

So this is a shared (managed) server. It is my understanding that each website hosted by the shared server is effectively in its own directory somewhere within the shared server. So what I need to do is redirect https://www.example.com to a URL that looks like it is on a different domain, although ultimately the files will be served from the same computer. The user should not see the modified URL though.

The hosting company told me to do it using mod rewrite - but unhelpfully said they couldn't support me in doing that though.

In the past I hosted an OSCommerce installation that did what I wanted to do now quite successfully, but there all I had to do was enter the redirect URL in one of the shop site's configuration pages, I never actually saw how it achieved it.

Am I making sense? I'm afraid I'm an embedded programmer, and only dabble in hosting stuff when I need to, so I may not be using the correct terminology, or explaining myself very clearly.

lucy24

4:12 pm on Jun 25, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Oh, the TLD doesn't matter, I was just asking about the URL. You confirmed my impression that you're supposed to rewrite to a different host. But now I've got conflicting explanations:
So what I need to do is redirect https://www.example.com to a URL that looks like it is on a different domain, although ultimately the files will be served from the same computer. The user should not see the modified URL though.
"Redirect" (external) means you send back a 300-class response ([R] flag in mod_rewrite) telling the browser to make a fresh request at a new URL. If you don't want the user to know that they're in a different place, that's an internal rewrite, not a redirect.

Ordinarily, internal rewrites in htaccess* happen within the same directory. You can rewrite using physical filepaths instead -- but only if you're in the config file (including VPS), and then of course you have to know what the physical filepath is.

If this is something your host does routinely, you would think that they would know exactly what instructions to give their users. I'd expect a checkbox in your Control Panel (whether CP or the host's own), or a wiki page detailing exactly what to say and where to say it. So it really seems as if there's something they're not telling you, or something they're saying incorrectly.


* Now that I've hit Preview, I can no longer see your original post. You did say htaccess, right?