re-direct / re-write my domain - .htaccess

First, I have already spent the past few hours trying to find a solution for this, but have had nothing but non-working solutions :(
It's pretty simple - I'm pointing the DNS of a new domain to my current hosting, but when I visit the new domain, I'm just viewing my original site (the one i got with my hosting).
Let's say my original site is "www.originalsite.com" - the content for my new domain is at "www.originalsite.com/newsite.com/" (dots included).
Now I just need to get "www.newsite.com" to re-direct to it's own directory AND re-write itself to hide the directory name.
So yeah, "www.newsite.com" needs to use the content in "www.originalsite.com/newsite.com/", but remain displayed as "www.newsite.com" in the URL bar.
Cheers for any input - really appreciated :)
PS: I'm using ColdFusion and previously made a useful re-direction, but the result was typically "www.netsite.com/newsite.com/" - which is not what I want :)
Oh...and yeah, I'm hoping for an .htaccess fix :) thanks!

If you have full control over the server, a VirtualHost in httpd.conf is probably a better solution. For example:
<VirtualHost newdomain.com:80>
ServerName newdomain.com
ServerAlias www.newdomain.com
DocumentRoot /path/to/webroot/newsite.com
</VirtualHost>
If you don't have the ability to do this directly, any good host will provide a "Park Domain" function which allows you to achieve the same effect - specifying your new domain and identifying which directory you want it to point to - via the web control panel.
However, if you don't have the ability to do that, here's a mod_rewrite for .htaccess that should work:
RewriteEngine On
RewriteCond %{REMOTE_HOST} (www\.)?newdomain\.com
RewriteRule ^(.*)$ /newdomain.com/$1 [L]

CrystalTech have just recentely installed a mod that provides htaccess ...
Though they've only done it one server so far :) so I'm being moved onto that server.
Problem solved I guess - heh!
PS thanks for the help anyway guys :)

You could do the redirect with a "cloaked" frame page.
That way the URL in the browser's address bar stays the same (no extra path), and it remains simple to use the subdirectory.
The following link describes this for classic ASP - but it should be simple to convert to any server side scripting language/platform:
http://www.simpledns.com/kb.aspx?kbid=1151

Related

mysite.com/new redirects to mysite.com

I just rebuilt my site to be responsive with Gantry 5 and Joomla. built in inmotion hosting server. moved it into a sub domain on my real sites server, www.umiultrasound.com/new. when i try to access the site to test it redirects to www.umiultrasound.com.
I have discussed this with my host, they say i have a wildcard redirect- i don't. they say to check my .htaccess file. i did but i do not see where i am redirecting / or www.mysite.com to itself.
they then recommended that i read one of your forum results. the one they sent didn't apply to me. hoping you can help
Check for any RewriteBase command in .htaccess. You could also temporarily copy the standard htaccess.txt over .htaccess to see if this makes any difference (backup .htaccess to .htaccess.old or similar first).
Also check your configuration.php file to see if the live_site parameter has been set.

.htaccess - Masking and redirecting to a subdirectory on a different server

I'm looking for some help with my .htaccess file.
In short, I have a bunch of content up in the subdirectory www.myserver.com/forum/ (this directory is not my choice and cannot be changed), which includes both a forum (myserver.com/forum/forum) and a wiki (myserver.com/forum/wiki) and this is abviously not an ideal layout. I do not own myserver.com and there is content there that is not mine, though I have full access to the entire server.
I also have a domain name www.mydomain.com, which I want to redirect and mask such that if a user goes to mydomain.com/<something> they will be shown the content from myserver.com/forum/<something> while still being shown mydomain.com/<something> in the address bar.
One other thing I'd like to see, although it isn't vital, would by for a 404 generated by someone typing in mydomain.com/somethingThatDoesNotExist should redirect to mydomain.com/404.php instead of myserver.com's default 404.
I've tried a number of different approaches and searched extensively for the past day or so online - I'm sure that the answer is even here on SO somewhere, but all of the guides/examples I've tried have not worked and I feel like I'm going in circles.
Many thanks in advance.
EDIT: And I do know for sure that .htaceess is enabled.
if a user goes to mydomain.com/ they will be shown the
content from myserver.com/forum/ while still being shown
mydomain.com/ in the address bar.
First thing you need to understand that this is ONLY possible if mod_proxy is enabled on the Apache server of mydomain.com.
Once you've enabled mod_proxy, mod_rewrite and .htaccess through httpd.conf on mydomain.com, put this code in its .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteRule ^(.*)$ http://myserver.com/$1 [L,P]
I will have to think little more about your 404 requirement, but if you get this working I am sure we can find a workaround for that as well.
You could do some proxying with PHP or whatever other language they allow..
Take a look at file_get_contents behind a proxy?

Changing a website domain and redirecting

We're moving a fairly large website from domain.one where it's been for a long time onto domain.two. If people still find links for domain.one we want them to redirect to an appropriate place on domain.two (if possible).
Domian.one is no longer required after the switch. I don't know anything about moving an entire domain so could use some advice on the best way to go about switching whilst retaining the SEO gained over the years.
Any help is appreciated.
Many thanks
Put this in an htaccess file in your root web directory. It will forward your users, and search engines, to the new URL on the new domain.
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
ADD THE FOLLOWING LINES as posted by John .
Also log in to google webmaster tools->configuration->change of address
and change your url ther so that seacrh engine results are also changed.
THIS iS VERY IMPORTANT

1 domain.. 2 server and 2 applications

i have a site like twitter.com on server one and on server two i have forum, which path is like domain.com/forum
on server one i wanted to implement wild card dns and put main domain on it. but on server two i wanted to keep forum separate, i cant give sub-domain forum.domain.com, because all its links are already put in search engines and link back to domain.com/forum.
so i was wondering, how can i put domain and wild card dns on server one and still able to give path on server 2 for domain.com/forum (as sub-folder).
any ideas?
do you think htaccess can do that job? if yes, then how?
You could use htaccess and mod_rewrite so domain.com/forum actually displays pages from forum.domain.com.
Maybe something like this:
Options +FollowSymLinks
RewriteEngine on
RewriteRule domain.com/forum/(.+) forum.domain.com/$1
Easy - use a proxy! If you like apache you will love apache mod_proxy for your purpose.
<VirtualHost *:80>
ServerName maindomain.com
ServerAlias *.maindomain.com
# insert document root and general settings for this domain here
# ...
ProxyPass /forum http://forumdomain.com
ProxyPassReverse /forum http://forumdomain.com
ProxyPassReverseCookieDomain forumdomain.com maindomain.com
</VirtualHost>
This configuration makes apache do a HTTP-request to your internal domain (forumdomain.com) without notifiying the users browser of the internal location. Your Forum will be accessable at http://*.yourdomain.com/forum. Cookies and headers the forum sents will get rewritten accordingly and Search-engines will not take notice of your backend-server.
You can read more about it at http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
Should you need to rewrite reference sin your html (href, src ...) you might google on "mod_proxy_html".
A solution like this could of course be build with other intelligent proxyservers like squid as well. You can use it to map any content from "backend servers" to your public domain.
Make sure routing is OK or set up a host-entry for your internal domain (forumdomain) with a internet ip-addresse 192.168 ...
Enjoy your site and give feedback how worked out :)
p.s.: a "RewriteRule" directive can potentially do the same thing for you but the rdirect will be visible (and executed) by the client unless you specify the "P", foricng it to do an internal proxy request. If available I would prefer the mod_proxy though as it is more versatile and allows for more configuration.
If you use a proxy on server 1 pointing to server2, you will increase the load on server 1, since all traffic will be routed through it. Besides, if server 1 goes down, nobody will be able to reach server 2 either. Of course it is possible though, but these things are to be considered.
I would suggest setting up a supdomain for server 2 anyway, like forum.domain.com, and on server 1 you set up a 301 redirect from domain.com/forum to forum.domain.com using mod_rewrite from htaccess. Using that technique, you can even redirect calls to specific links to their corresponding page on server 2. Search engines will follow the 301 and they will eventually update the index.
You can use a 301 redirect to make sure the search engine update their index with your new urls like so:
RewriteRule domain.com/forum/(.*) http://forum.domain.com/$1 [R=301,L]
If you've got two servers you don't really have much choice but to use a redirect (ideally a 301 Permanent redirect) to move users from domain.com/forum to forum.domain.com.
The only other way to do it would be to put a reverse proxy in front of those two servers, which reads the URL and internally directs the query to the right server, but that's then an extra piece of hardware.

Domain redirect Problem

I have a website say domain.old hosted with say 'host-old'
I want to do away with 'host-old' and go with 'host-new'
(so effectively 'host-old' hosting would end)
Also I want a new domain - say 'domain.new'
So now I have 'domain.old' , 'domain.new' and 'host-new' with me
Now I want all my old links are preserved:
viz. http://domain.old/cat1/link1/page1/
redirects to http://domain.new/cat1/link1/page1/
Now please advice what would be the best way to go to set up with the new host.
This is a multi-step process:
Create all the pages at 'host-new' so that 'http://domain.new/cat1/link1/page1/' all work.
Enable mod_rewrite in Apache on 'host-new', and configure as below.
Change the dns entries for 'domain.old' to point to 'host.new'
wait 2-3 days for dns entries to propagate to remainder of the internet.
stop hosting at 'host-old'
The mod_rewrite config you need is:
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.old$
RewriteRule ^(.*)$ http://domain.new/$1 [NE,R=301,L]
i don't know exactly how this would work but you could parse the URL from the old site and redirect to your new host. You need a common script in your domain.old masterpage that does this for you.
The question would be easier to answer if you specified your platform. If you are on Apache, I'd take a look at mod_rewrite
You'll probably want to provide a 301 (moved permanently) http response.
When you get rid of the old domain, you can't control it any more, and therefore won't get traffic from it. You should transfer the old domain to your new host (not too hard), and then have a redirector running on it - the way other answers suggest.

Resources