Forum Moderators: phranque

Message Too Old, No Replies

redirect http://*.olddomain.com to https://*.old-domain.com

redirect to https with wildcard site

         

csgonan

5:34 pm on Jun 9, 2009 (gmt 0)

10+ Year Member



I need to redirect all references to *.olddomain.com to [*.old-domain.com...] (with a dash). The site is a wildcard and they can enter anything for * so they have to not lose the vaue of * when redirecting.

I also need to redirect all references of [*.old-domain.com...] to [*.old-domain.com....] Again I do not want to lose the value of * that they typed in.

I can do this with redirect or rewrite, whichever is easier please.

Thank you

jdMorgan

6:31 pm on Jun 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please see our Forum Charter [webmasterworld.com] for information on how to get the most from this discussion forum.

Your correspondents will also need to know if the old and new domains are hosted separately, or in the same 'account space' of the same server. If they are co-hosted, then you cannot use 'Redirect' without creating an 'infinite' redirection loop.

Jim

csgonan

7:17 pm on Jun 9, 2009 (gmt 0)

10+ Year Member



Hello,

There are 2 sites on the same server. Apache v2.2.11, Solaris.

I have a new domain my-domain.com, which can have any prefix (sitea.my-domain.com, siteb.my-domain.com). Apache is simply defined with *:80, *:443 ServerName *.my-domain.com. This works fine.

If the user enters sitea.mydomain.com (withouth the dash), I want to redirect them to [sitea.my-domain.com,...] although I do not know the value of sitea. Also, if they enter [sitea.my-domain.com,...] I want to send them to the same https site, but again, I do not know the value of sitea.

I had seen some examples of using $1. like this, but I don't know the syntax, or whether to use RewriteMatch.

RewriteRule (*).mydomain.com [$1.my-domain.com...] but it doesn't like that syntax.

There is one site on this server I do not want https (site.company.com).

I hope this is the correct format for presentation of the question. Thank you for your help.

jdMorgan

7:56 pm on Jun 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Still not sure if the domains you don't want redirected share the same filespace as those that you do or not.

Also, we need to know where you intend to put this code, as the syntax changes depending on whether you put it in .htaccess, inside a <directory> container in httpd.conf (or other config file) or outside of any <directory> container.

Do you have any other currently-working rewriterules in that location?

"Keeping" the subdomain and the requested URL-path is trivial, but a lot of background details are needed to determine a correct solution.

Jim

csgonan

8:36 pm on Jun 9, 2009 (gmt 0)

10+ Year Member



Hello,

Thank you for responding. They are the same server, same file space. If someone enters sitea.mydomain.com I want them redirected to [sitea.my-domain.com....] It is not another machine

I tried this and didn't get any errors but it didn't bring up the secure site with the proper domain. I didn't even get anything in my rewrite log.

RewriteRule ([^/.]+).mydomain [$1.my-domain.com...]

I have not done rewriting before. Would redirect be better?

thanks

jdMorgan

8:50 pm on Jun 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're not answering my questions, and unfortunately, that makes it impossible to answer yours without making assumptions. And that's generally a waste of time...

You will need to use a regular-expressions pattern in a RewriteCond testing %{HTTP_HOST} to test and extract the subdomain name. For the case where the domain is correct but the protocol may be wrong, you will need to use a RewriteCond to examine %{SERVER_PORT}.

You will also likely want to create and use a back-reference to the requested URL-path (e.g. the 'page') so that you land on the same page as requested, but in the proper domain and using the proper protocol.

Jim

csgonan

9:23 pm on Jun 9, 2009 (gmt 0)

10+ Year Member



Hi, I"m sorry if I'm not being clear. The sites have the same DocumentRoot. The user types in sitea.mydomain.com and I want to send them to sitea.my-domain.com. The ServerName directive in vhost is *.my-domain.com. Also if they try to access the site on 80 I want to redirect them to 443.

I have tried many things, and it doesn't seem to be executing the expression.

First I had RewriteRule but that didn't work. I tried this too. The modules are compiled. I even put in a vhost for ServerName *.myserver.com with the redirect in there and it isn't working.

Is this expression correct?

RedirectMatch ([^/.]+).myserver.com [$1.my-server.com...]

Again, thank you.

jdMorgan

10:02 pm on Jun 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, none of these directives can examine the hostname. They only 'see' the URL-path, as is made clear in the modules' documentation. This is a problem with rushing from research and requirements specification to implementation.

Lacking any direction, I will assume you're trying to put this code into a config file within a VirtualHost container, rather than in .htaccess or within a <Directory> container.

You will need to restart the server after changing/uploading this code.

In httpd.conf, not within any <Directory> container


Options +FollowSymLinks
RewriteEngine on
#
# Externally redirect olddomain.com subdomain and non-canonical old-domain.com FQDN
# requests or requests with appended port numbers to canonical domain using SSL
RewriteCond %{HTTP_HOST} ^(([^.:]+\.)*)olddomain\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(([^.:]+\.)*)old-domain\.com\.$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(([^.:]+\.)*)old-domain\.com\.?:[0-9]+$ [NC]
RewriteRule ^/(.*)$ https://%1old-domain.com/$1 [R=301,L]
#
# Externally redirect non-SSL requests for old-domain.com or requests
# with uppercase characters in hostname to canonical domain using SSL
RewriteCond %{SERVER_PORT} !=443 [OR]
RewriteCond %{HTTP_HOST} [A-Z]
RewriteCond %{HTTP_HOST} ^(([^.:]+\.)*)old-domain\.com [NC]
RewriteRule ^/(.*)$ https://%1old-domain.com/$1 [R=301,L]

Jim

[edited by: jdMorgan at 2:51 am (utc) on June 10, 2009]