Page 1 of 1

Url Rewriting

Posted: Tue Sep 16, 2014 1:55 am
by vmpriyan
Hi,

I have 2 domains "first.com" and "second.com" (both are pointed to same server).
I hosted a site under "first.com". When I type the url "second.com", the site should redirect to "first.com" but in address bar it should show only "second.com".
I tried the following code in .htaccess file, and its redirecting to first.com but url is also changing as first.com.

RewriteCond %{HTTP_HOST} ^second\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.second\.com$
RewriteRule ^/?$ "http\:\/\/first\.com\/" [R=301,L]

I want to show the url as second.com but redirect to first.com.

Anybody pls help me to achieve this.

Re: Url Rewriting

Posted: Tue Sep 16, 2014 3:54 am
by requinix
Don't attempt any redirection at all. Because redirection, as the word implies, will redirect the user, and you don't want them to redirect. You want them to stay exactly where they are.

Make sure your Apache vhost is set up to accept both domain names for the site (ie, with a ServerName and a ServerAlias) and then make sure your application doesn't redirect - or if it must, redirects using either an absolute path without the domain name or a completely absolute URI using the current domain name (which you can find in $_SERVER["HTTP_HOST"]).

Re: Url Rewriting

Posted: Tue Sep 16, 2014 4:13 am
by vmpriyan
Thank you Requinix for your reply,

But actually as per my requirement, I need to hide the typed url, (if a user types second.com, the site first.com should be served, and the typed url should not be changed).
Any idea to get this?

and I'm using a shared hosting.

Thank you

Re: Url Rewriting

Posted: Tue Sep 16, 2014 4:22 am
by requinix
Yes, and what I said fits that exactly.

Except you're using shared hosting. That makes it harder. If you have (a) both servers on the same account (b) and on the same physical machine, (c) shell access, and (d) some luck, you may be able to do it. Otherwise you should look into dedicated hosting options.