Forum Moderators: phranque
I feel silly as if I'm having problems putting two and two together from all the mod_rewrite documentation and examples out there, but I was wondering how to get this done.
I have two domains, a short one I moved off of (and now have a whopping 2MB of space on thanks to a donation from a friend), and a long one I use now. Unfortunately, this second one is much longer and apparently one of the HARDEST words to type on the Internet (I'd say why, but it'd sidetrack the point). So basically, I want to make it so that when anybody uses the old domain (which is easy to type and remember), it will simply redirect the request to the new one (the latter part of which is left-pinky intensive).
I use this .htaccess currently:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP-HOST}!^www\.as\.tld
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)$ http://www.asdfasdfasdfasdf.tld/$1?%1 [R=permanent,L]
(If it's OK to give a real-life example of this in action, sf.net/sourceforge.net is set up this way)
Thanks,
BRPXQZME
- you'll of course have to do minor edits to get it working. I think you'll get by by changing it to something like this (it's just a quick edit):
-------------------------------------------
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?[^.]+\.as\.tld
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^(www\.)?([^.]+)\.as\.tld(.*) http://$1.asdfsdsds.tld/$2 [R=301,L] This might even do the whole thing by itself - at least as far as subdomains are concerned. Give it a try and let's hear if it works for you. Oh, this might need to be changed:
From [^.] to [^\.] but i'm not sure it really needs to.
/claus
Just to make it really, really clear what should happen:
[[(1).]as.tld[...] -->
[[(1).]asdfasdfasdfasdf.tld[...]
Of course it isn't rocket science. It's quantum physics as far as I know :P
Let's try this one, i hope it's a little closer (i'll skip the options symlinks and the rewrite engine, they should be there as well):
-------------------------------------------
RewriteCond %{HTTP_HOST} as\.tld$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^(.*)?as\.tld(.*) http://$1asdfsdsds.tld/$2 [R=301,L] The condition is matched as long as the domain ends in "as.tld"
Rule 1: Anything after the host name is appended to the host name and the whole thing is chained to rule 2
Rule2: Anything between the start of the string and "as" is put before the long domain and anything after "tld" is put after "tld" on the long domain.
At least that's what it's supposed to do - i hope it does it as well this time. I'm off for now, but i'll pop in tomorrow, it's 3AM here.
Added: Just saw the shorter version in post #4. If that one works, use it in stead - unnecessary complexity is not good.
/claus
One of the problems here is that it's not completely clear what your possible 'short' domain names look like, and what the 'long' output for each of those should be. It might be helpful if you posted a list like
www.as.tld -> www.asdf.tld
as.tld -> www.asdf.tld
test.as.tld -> www.asdf.tld/test
etc.
showing as many unique variations as possible.
Jim