Discussion:
HTTP headers and header()
(too old to reply)
Sandman
2012-01-13 20:47:30 UTC
Permalink
Hello,
I run a website which allows users to create profiles for
themselves, i.e. example.com/user. Recently I've had a request for
custom domains, i.e. where vanity.user.com would take a browser to
example.com/user.

Using my own domain, I changed vanity.user.com so it resolves to
the IP address of my webserver. Since I run apache, I created a
RewriteRule so if the HOST header matched vanity.user.com it would
redirect permanently to example.com/user.

Upon redirection however, the location bar in my browser updates
to example.com/user. Does anyone know if there is a way to:

1. Redirect the vanity domain to the user's profile.
2. Keep the location bar the same (i.e. vanity.user.com)

I'm cross-posting to comp.lang.php because I was wondering if the
header() function might help.

Thanks!
Sandman
The Natural Philosopher
2012-01-13 22:07:07 UTC
Permalink
Post by Sandman
Hello,
I run a website which allows users to create profiles for
themselves, i.e. example.com/user. Recently I've had a request for
custom domains, i.e. where vanity.user.com would take a browser to
example.com/user.
Using my own domain, I changed vanity.user.com so it resolves to
the IP address of my webserver. Since I run apache, I created a
RewriteRule so if the HOST header matched vanity.user.com it would
redirect permanently to example.com/user.
Upon redirection however, the location bar in my browser updates
1. Redirect the vanity domain to the user's profile.
2. Keep the location bar the same (i.e. vanity.user.com)
I'm cross-posting to comp.lang.php because I was wondering if the
header() function might help.
Thanks!
Sandman
set up an apache virtual server and do the thing properly
M. Strobel
2012-01-13 22:32:04 UTC
Permalink
Post by Sandman
Hello,
I run a website which allows users to create profiles for
themselves, i.e. example.com/user. Recently I've had a request for
custom domains, i.e. where vanity.user.com would take a browser to
example.com/user.
Using my own domain, I changed vanity.user.com so it resolves to
the IP address of my webserver. Since I run apache, I created a
RewriteRule so if the HOST header matched vanity.user.com it would
redirect permanently to example.com/user.
Upon redirection however, the location bar in my browser updates
1. Redirect the vanity domain to the user's profile.
2. Keep the location bar the same (i.e. vanity.user.com)
I'm cross-posting to comp.lang.php because I was wondering if the
header() function might help.
Thanks!
Sandman
Get acquainted with Apache VirtualServer and ServerName directives.

/Str.
M. Strobel
2012-01-13 22:33:46 UTC
Permalink
Post by M. Strobel
Post by Sandman
Hello,
I run a website which allows users to create profiles for
themselves, i.e. example.com/user. Recently I've had a request for
custom domains, i.e. where vanity.user.com would take a browser to
example.com/user.
Using my own domain, I changed vanity.user.com so it resolves to
the IP address of my webserver. Since I run apache, I created a
RewriteRule so if the HOST header matched vanity.user.com it would
redirect permanently to example.com/user.
Upon redirection however, the location bar in my browser updates
1. Redirect the vanity domain to the user's profile.
2. Keep the location bar the same (i.e. vanity.user.com)
I'm cross-posting to comp.lang.php because I was wondering if the
header() function might help.
Thanks!
Sandman
Get acquainted with Apache VirtualServer and ServerName directives.
/Str.
Ops, VirtualHost
Arno Welzel
2012-01-14 01:40:11 UTC
Permalink
Post by Sandman
Hello,
I run a website which allows users to create profiles for
themselves, i.e. example.com/user. Recently I've had a request for
custom domains, i.e. where vanity.user.com would take a browser to
example.com/user.
Using my own domain, I changed vanity.user.com so it resolves to
the IP address of my webserver. Since I run apache, I created a
RewriteRule so if the HOST header matched vanity.user.com it would
redirect permanently to example.com/user.
Upon redirection however, the location bar in my browser updates
1. Redirect the vanity domain to the user's profile.
2. Keep the location bar the same (i.e. vanity.user.com)
This is not possible. *Either* redirect *OR* keep the location.

If you don't want this, you have to set up a virtual host in Apache
which acts as a proxy for example.com/user.
--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
Sandman
2012-01-14 02:58:32 UTC
Permalink
Thanks Arno. I thought as much, but thank you for confirming.

I had wanted vanity.user.com to resolve to example.com/user.
It seems there are only 2 possible half-solutions:
1. Use redirects, which change the location bar as I mentioned
originally.
2. Use VirtualHosts which does not change the location bar. But with
this solution, vanity.user.com/user resolves to example.com/user.
Which is not really what I wanted.

Ah well, my users will have to live with this.

Regards,
Sandman
Post by Arno Welzel
Post by Sandman
Hello,
   I run a website which allows users to create profiles for
themselves, i.e. example.com/user. Recently I've had a request for
custom domains, i.e. where vanity.user.com would take a browser to
example.com/user.
   Using my own domain, I changed vanity.user.com so it resolves to
the IP address of my webserver. Since I run apache, I created a
RewriteRule so if the HOST header matched vanity.user.com it would
redirect permanently to example.com/user.
    Upon redirection however, the location bar in my browser updates
1. Redirect the vanity domain to the user's profile.
2. Keep the location bar the same (i.e. vanity.user.com)
This is not possible. *Either* redirect *OR* keep the location.
If you don't want this, you have to set up a virtual host in Apache
which acts as a proxy for example.com/user.
--
Arno Welzelhttp://arnowelzel.dehttp://de-rec-fahrrad.de
J.O. Aho
2012-01-14 07:51:53 UTC
Permalink
Post by Sandman
2. Use VirtualHosts which does not change the location bar. But with
this solution, vanity.user.com/user resolves to example.com/user.
Which is not really what I wanted.
Thenk yo haven't set up the virtualhost correctly, instead of redirecting with
mod_rewrite, you set the documentroot to the actual directory which is the
same as it would have been for example.com/user.
If the directory depends on a CMS, then you need to employ the usage of
mod_proxy in the virtualhost, which fetches the files from example.com/user.

In both these cases the domain will be kept as the original one which the
visitor typed in the browser.


Did set the follow up to alt.apache.configuration as that is the newsgroup
where this thread should have been all the time.
--
//Aho
Arno Welzel
2012-01-14 09:37:13 UTC
Permalink
Post by Sandman
Thanks Arno. I thought as much, but thank you for confirming.
I had wanted vanity.user.com to resolve to example.com/user.
1. Use redirects, which change the location bar as I mentioned
originally.
2. Use VirtualHosts which does not change the location bar. But with
this solution, vanity.user.com/user resolves to example.com/user.
Which is not really what I wanted.
Why is it neccessary to use vanity.user.com/user?

BTW: Please learn, how to quote properly in usenet postings (quotation
above, reply below) - thanks!
--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
The Natural Philosopher
2012-01-14 11:09:24 UTC
Permalink
Post by Sandman
Thanks Arno. I thought as much, but thank you for confirming.
I had wanted vanity.user.com to resolve to example.com/user.
1. Use redirects, which change the location bar as I mentioned
originally.
2. Use VirtualHosts which does not change the location bar. But with
this solution, vanity.user.com/user resolves to example.com/user.
Which is not really what I wanted.
Bullshit. Set the root directory of example.com to be the same directory
as vanity.user.com/user

You are just being lazy.
Jonathan Stein
2012-01-14 14:26:12 UTC
Permalink
Post by Sandman
Using my own domain, I changed vanity.user.com so it resolves to
the IP address of my webserver. Since I run apache, I created a
RewriteRule so if the HOST header matched vanity.user.com it would
redirect permanently to example.com/user.
How did you do this? Rewrites should not issue a redirect unless you
specifically ask for it (with the "R" flag in Apache).

Now that you're posting in the PHP group, you could also rewrite ALL
requests that do NOT have example.com as the host to a PHP script and
let that script look op the userprofile to show.

Start with the Apache documentation - there ain't much you can't do with
a rewrite. ;-)

Regards

Jonathan
Miquel van Smoorenburg
2012-01-20 15:34:56 UTC
Permalink
Post by Sandman
Upon redirection however, the location bar in my browser updates
1. Redirect the vanity domain to the user's profile.
2. Keep the location bar the same (i.e. vanity.user.com)
Sure. Use mod_rewrite, match on the Host header, and alias
to /user/

Say you want to map USER.vanity.com -> example.com/USER :

RewriteCond %{HTTP_HOST} ^(.*)\.vanity\.com$ [NC]
RewriteRule ^/(.*)$ /%1/$1

If you use this in a VirtualHost section make sure you
set ServerAlias *.vanity.com.

You might want to exclude /cgi-bin or other paths from this
specifically, you might want to add the [PT] flags to the
rewriterule .. see http://httpd.apache.org/docs/current/mod/mod_rewrite.html
for the details

Assuming apache, ofcourse.

Mike.

Loading...