LimpyNuts All American 16859 Posts user info edit post |
I haven't used PHP in about 3 years and consequently have forgotten pretty much everything but basic syntax. I just started up an apache server and I need to redirect based on the requested URL. i.e.
blah.no-ip.org woot.no-ip.org noob.no-ip.org
(not the real hostnames) all point to the same server. I want to redirect based on the hostname like this:
http://blah.no-ip.org > http://blah.no-ip.org/blah
and so forth. That's all I want index.php to do.
I want the index to redirect based 2/8/2006 4:10:35 PM |
spöokyjon ℵ 18617 Posts user info edit post |
You don't want to use Apache to do this? 2/8/2006 4:15:14 PM |
agentlion All American 13936 Posts user info edit post |
yar http://www.javascriptkit.com/howto/htaccess7.shtml 2/8/2006 4:17:39 PM |
LimpyNuts All American 16859 Posts user info edit post |
i don't know where the apache configuration files are stored under linux.
i used apt-get to install apache, so all I know is the www root is /var/www
[Edited on February 8, 2006 at 4:24 PM. Reason : ] 2/8/2006 4:22:46 PM |
Noen All American 31346 Posts user info edit post |
its called putting a .htaccess file in your root web folder. 2/8/2006 4:24:44 PM |
agentlion All American 13936 Posts user info edit post |
see ^^ you can add a .htaccess file to your root directory. That will take care of it 2/8/2006 4:24:47 PM |
dFshadow All American 9507 Posts user info edit post |
it'd be better to do it in apache than PHP 2/8/2006 4:24:47 PM |
agentlion All American 13936 Posts user info edit post |
wow - 3 responses in 3 seconds. not bad 2/8/2006 4:25:28 PM |
LimpyNuts All American 16859 Posts user info edit post |
sorry... it's been a few years since ive done this 2/8/2006 4:26:57 PM |
YOMAMA Suspended 6218 Posts user info edit post |
if its Fedora:
/etc/httpd/conf/httpd.conf
Just edit the:
DocumentRoot /home/your user/public_html/blah
and your done
[Edited on February 8, 2006 at 4:37 PM. Reason : op] 2/8/2006 4:36:00 PM |
LimpyNuts All American 16859 Posts user info edit post |
^x8 doesn't do what I want...
I want to redirect http://blah.no-ip.org to http://blah.no-ip.org/blah .
The redirect command doesn't let me discriminate between
blah.no-ip.org woot.no-ip.org noob.no-ip.org
I can
Redirect / http://blah.no-ip.org/blah
but then all 3 redirect to http://blah.no-ip.org/blah
[Edited on February 8, 2006 at 4:39 PM. Reason : ]2/8/2006 4:38:21 PM |
agentlion All American 13936 Posts user info edit post |
well i suck at redirects, but i'm sure it can be done. Someone else here can work up the regexs needed 2/8/2006 4:51:08 PM |
LimpyNuts All American 16859 Posts user info edit post |
I used a virtual host because it's better than having a .htaccess in the root. (.htaccess in the root will be loaded every time a page is requested. the defualt config is only loaded once)
<VirtualHost [ip address/* for any]> ServerName blah.no-ip.org DocumentRoot /var/www/blah </VirtualHost> 2/8/2006 4:59:25 PM |
spöokyjon ℵ 18617 Posts user info edit post |
That's what I've always done. 2/8/2006 5:09:40 PM |
dFshadow All American 9507 Posts user info edit post |
yeah, it's called virtual hosts in Apache: http://httpd.apache.org/docs/2.0/mod/core.html#virtualhost
in PHP, you can do a simple redirect page like this:
<?php $url = $_SERVER['HTTP_HOST']; switch ($url) { case "blah.no-ip.org": { header("location:http://blah.no-ip.org/blah"); break; } case "woot.no-ip.org": { header("location:http://blah.no-ip.org/woot"); break; } case "noob.no-ip.org": { header("location:http://blah.no-ip.org/noob"); break; } } exit; ?> HTTP_HOST gives you the host without http:// and not the file name after the host - for that, use REQUEST_URI2/8/2006 5:52:19 PM |
scrager All American 9481 Posts user info edit post |
mod rewrite will do what you want: http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html 2/8/2006 9:34:26 PM |