Forum Moderators: phranque
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
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
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.
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
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
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
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.
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]
[edited by: jdMorgan at 2:51 am (utc) on June 10, 2009]