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.orgwoot.no-ip.orgnoob.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/blahand 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
You don't want to use Apache to do this?
2/8/2006 4:15:14 PM
yar http://www.javascriptkit.com/howto/htaccess7.shtml
2/8/2006 4:17:39 PM
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
its called putting a .htaccess file in your root web folder.
2/8/2006 4:24:44 PM
see ^^you can add a .htaccess file to your root directory. That will take care of it
2/8/2006 4:24:47 PM
it'd be better to do it in apache than PHP
wow - 3 responses in 3 seconds. not bad
2/8/2006 4:25:28 PM
sorry... it's been a few years since ive done this
2/8/2006 4:26:57 PM
if its Fedora:/etc/httpd/conf/httpd.confJust edit the:DocumentRoot /home/your user/public_html/blahand your done[Edited on February 8, 2006 at 4:37 PM. Reason : op]
2/8/2006 4:36:00 PM
^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 betweenblah.no-ip.orgwoot.no-ip.orgnoob.no-ip.orgI can
Redirect / http://blah.no-ip.org/blah
2/8/2006 4:38:21 PM
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
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.orgDocumentRoot /var/www/blah</VirtualHost>
2/8/2006 4:59:25 PM
That's what I've always done.
2/8/2006 5:09:40 PM
yeah, it's called virtual hosts in Apache: http://httpd.apache.org/docs/2.0/mod/core.html#virtualhostin 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;?>
2/8/2006 5:52:19 PM
mod rewrite will do what you want:http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html
2/8/2006 9:34:26 PM