Forum Moderators: phranque
I am totally new for LAMP platform. Our company has a website where we use subdomains through mod rewrite. We have a folder "subd" in main root directory and with in this folder we have another folders like forum, blog etc which we use for subdomain.
Our problem is when we type in browser like [forum.example.com...] then its work but when we type [forum.example.com...] then it not work and show the main page of website www.example.com.
I want that in both cases(with or without www)we go forum section.
Here my code for rewrite
RewriteEngine On
rewriteCond %{REQUEST_URI}!^/subd
rewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com
rewriteCond /home/example/public_html/sudb/%1 -d
rewriteRule ^(.*)$ /sudb/%1/$1 [l]
The code of home page of the website
<?php
$domain = "example.com";
$sub = $_SERVER['HTTP_HOST'];
$sub = eregi_replace("\.".$domain, "", $sub);
$sub = eregi_replace("www\.", "", $sub);
$sub = strtolower($sub);
$docroot = $_SERVER['DOCUMENT_ROOT'];
if (is_dir("$docroot/$sub"))
{
header("Location: [$domain...]
exit;
}
else
{
include "index-main.php";
}
?>
I don't know the connection between both two codes.
I appriciate any help in this regard.
Thank you to all in advance.
Himanshu
Another problem with the original code is that it will map "www.example.com" to the subdirectory www if it exists. If it that subdirectory does not exist and will never exist, then a lot of time is wasted checking the filesystem to see if it exists -- even though the end result is that it is always mapped to the main domain space in the end. A new RewriteCond addresses this problem.
RewriteCond %{REQUEST_URI} !^/subd
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com
RewriteCond /home/example/public_html/sudb/%2 -d
RewriteRule (.*) /sudb/%2/$1 [L]
Jim
I appriciate any further help in this regard.
Himanshu
Many thanks to you. You rock man.
Himanshu