Miro
Miro

Reputation: 8650

PHP Redirect handler - keep URL and URI and fetch content from another URL

You've probably seen it on websites where they offer a website and you can use your own domain name if you want. So you register a www.website.com/user but you can also set up yourdomain.com to redirect [with A record] to Website_IP_ADDRESS and they handle it because you gave them your domain (www.yourdomain.com) so they know to redirect to www.website.com/user but your address bar remains www.yourdomain.com

krop.com has it

This is what I've been trying to do: enter image description here

I want to be able to handle incoming redirects from multiple websites and 'fetch' content from a subfolder on the main site but keep the original URL intact.

I want to use php since i want to retrieve the user var (bar and foo) from a db.

Since I won't have access to every domain, I can only play with the incoming part (the blue box)

So far I only had success with duplicating a url (www.bar.com fetches 75.333.444.55) which is pretty useless...

And using file_get_contents('http://address') in my index.php to display subfolder index.html without redirecting again but it's slow and browser unfriendly.

I've been trying to ".htaccess it" with little success

Anything will help

Thanks

Upvotes: 0

Views: 1066

Answers (2)

Miro
Miro

Reputation: 8650

Thanks Ariel

here is what happened: I added the following code to /etc/httpd/conf/httpd.conf

<VirtualHost *:80>
DocumentRoot /var/www/vhosts/website.com/httpdocs/users/foo 
ServerName www.foo.com 
ServerAlias *.foo.com
</VirtualHost>

AddHandler php-script   .php

Works like charm! :)

Don't forget to restart apache to take effect. On mediatemple it is: /etc/init.d/httpd restart

Upvotes: 0

Ariel
Ariel

Reputation: 26753

You do not want a 302 redirect! You want a virtual host.

Google for virtual host and if you need more help ask - but make sure you tell us what webserver you are using.

Upvotes: 1

Related Questions