We help IT Professionals succeed at work.

Silent or invisible or transparent redirect (.htaccess or different)

R-U-Bn
R-U-Bn asked
on
9,912 Views
Last Modified: 2008-01-09
Hello,

I try to do the following:  
When a user types ..
         http://www.tec4dec.be(anything here)  (let's call this A)
...he would come to...
         http://tec4dev.be/www(anything here)  (let's call this B)
.. BUT without the user seeing B in his address bar or as URL. So the user would still see A!

The following works, but is not silent (so the user sees B): in .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.tec4dev.be [NC]
RewriteRule ^(.*)$ http://tec4dev.be/www/$1 [L,R=301]  

When I remove the ",R+301" I get a 500 Internal Server Error .

Please help!

Comment
Watch Question

CERTIFIED EXPERT

Commented:
I use alias's for this function so when people type in www.chilternpc.co.uk  they get www.chilternpc.com  content, but the address is still www.chilternpc.co.uk

so can you not set  "web addressA" as an alias to "websaddressB"

to do this in apache see
http://forums.macosxhints.com/showthread.php?t=45712


Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
you are correct -
if you have a hosting provider do they provide an interface to set up alias's?

try
<Host name="www.mycompany.com" ...>
  ...
  <Alias>mycompany.com</Alias>
  ...
</Host>



Commented:
hi R-U-Bn,

When a user types ..
         http://www.tec4dec.be(anything here)  (let's call this A)
== I would assume that there is a slash (/) after the ".be". otherwise DNS resolution may failed.
         http://www.tec4dec.be/(anything here)  (let's call this A)

mod_rewrite should be able to do the job, like you posted.  However, I have very limited skills on that.

I am personally more comfortable to propose using the ProxyPass/ProxyPassReverse for this.

http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypassreverse

<VirtualHost *>
  ServerName www.tec4dev.be
  ServerAlias tec4dev.be
  ProxyPass            /     http://tec4dev.be/www/ 
  ProxyPass            /     http://tec4dev.be/www/
</VirtualHost>

in the respective server Vhost container for      www.tec4dec.be

cheers.

Author

Commented:
samri, I get a Server Error with your code.. (I should put that in .htaccess, right?)
Are you sure nothing is lacking (like  ProxyRequests On or so?) or you need 2 times the same line there?
Secondly, do you know if your solution is better than mine?

Commented:
hi R-U-Bn,

sorry for taking a bit while to respond.

You would need to add it to the server config.  What is your server OS, and apache version by the way?

You also may want to check the docs for mod_proxy - http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

You would need to load the proxy module first.  In the config file (httpd.conf), look for the following line, and uncomment it (remove the # in the beginning of the line).

LoadModule proxy_module modules/mod_proxy.so

However!! If I relook at the initial question text;

When a user types ..
         http://www.tec4dec.be(anything here)  (let's call this A)
...he would come to...
         http://tec4dev.be/www(anything here)  (let's call this B)
.. BUT without the user seeing B in his address bar or as URL. So the user would still see A!

what you wanted to do is having the user visiting http://www.tec4dec.be/anylink/any.html and the content is served from:

http://tec4dev.be/www/anylink/any.html

So rather than complicating the subject, It would be easier to reconfigure the DocumentRoot for the server wherever the "www" forlder is.

And, in apache config, look at ServerName and ServerAlias directive.  In your case, you could do

ServerName tec4dev.be
ServerAlias   www.tec4dev.be

DocumentRoot /path/to/www

Theese needs to be in httpd.conf, and not .htaccess file.  The rewrite rule would work in .htacces though.

cheers.

Author

Commented:
I see now, samri.  Like I said, I am using a hosting provider, so I don't have access to those configs you are talking about. (www is even pre-programmed elsewhere)  I presume it won't work with your solution then..
Thanks anyway. :-}

Commented:
hi R-U-Bn,

my apology on missing that fact :(.

Perhaps you could highligh this to you Hosting provider.  

Typically, most hosting provider would implement VirtualHosting for the client websites.  As such, the ServerName and ServerAlias directive should be in place, or could be added.

And the thing about contents coming from /path//www/ is DocumentRoot (or web home, or anything they may called it).  Should also be configurable.

Mod_rewrite, should be able to do this, and could be used in .htaccess file.  However, I do not have that much knowledge on that unfortunately.

There are docs docs/guide on Apache website that you could take a look:

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html
http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide_advanced.html

** which I had spent some time, and doesn;t quite make it into my head :(


Cheers,
CERTIFIED EXPERT

Commented:
I use alias all the time with my hosting company - this is how it works with mine - it may help -

register ALL the domain names  with your hosting company then  
use one of them as the host  and upload your files and set up all the others as alias's to this one
This is done using the hosting company's interface during domain registration

Author

Commented:
Admin, please remove or mark as self-answered.
Thanks.

Anyone any objeftions?
CERTIFIED EXPERT

Commented:
you managed to answer it by asking this forum -  see your previous comments

Author

Commented:
I completely agree.  But since I can't mark my own answer as answer (possibly with you getting the points as support), xX possibilities doesn't allow me to do this properly.

Let's do it like this maybe, chilternPC, just repeat my answer and I can accept your repetition, agree?
CERTIFIED EXPERT

Commented:
you can split the points to everyone you consider helped you to your answer. or you can ask for a point point refund here:
https://www.experts-exchange.com/Other/Community_Support/Top_Solutions_3.html

Author

Commented:
You don't understand, chilternPC, I want to give you points, but with my answer.  For future users, you know, to allow them a correct answer.  And at the same time giving you points for pointing me the right way.  For that, there is no way in xX, except what I proposed.

It's your last chance, better take it.  ;-)
CERTIFIED EXPERT

Commented:
Closed, 445 points refunded.
modus_operandi
EE Moderator
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.