Reputation: 531
I already searched for many tutorials and nothing worked to me. I want create virtual subdomains with htacces but when I enable mod_rewrite my software disable the original urls. For example:
mod_rewrite disabled:
http://domain.com/listings.php?category=35
mod_rewrite enabled:
http://domain.com/35-finance/listings.html
When enabled I can't acces http://domain.com/listings.php?category=35...
In my htacces, if mod_rewrite disabled, this works:
RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-_]+).domain.com [NC]
RewriteRule (.*) listings.php?category=%2 [NC,QSA]
But if enabled, it don't work, it don't understand the 'category' parameter.
I tried this:
RewriteRule (.*) http://www.domain.com/%1/listings.html [L]
I'm redirected to the correct page, but I want to keep the subdomain in the browser bar...
I tried this:
RewriteRule (.*) /%1/listings.html [L]
It results in internal server error.
I really tried many things before in this week, but nothing works...
Upvotes: 0
Views: 223
Reputation: 531
I got solve the problem using this php code: (www.gitme.net/php/ >> Gitme url2subdomain )
<?php
// code by büyücü. www.gitme.net/php/
$full_url = sprintf($HTTP_HOST);
$subdomain = "";
for($i = 0;$i<=strlen($full_url);$i++)
{
$dummy = substr($full_url,$i,1);
if($dummy == ".")
{
break;
}
$subdomain = $subdomain.$dummy;
}
//
if ($subdomain <> "www")
{
switch($subdomain)
{
case "gazeteler":
$real_url = "http://www.gitme.net/gazeteler.htm";
break;
case "guzel-sozler":
$real_url = "http://www.gitme.net/guzel-sozler.php";
break;
case "burclar":
$real_url = "http://www.gitme.net/burclar.html";
break;
default : $real_url="http://www.gitme.net/";
}
include "$real_url";
exit;
}
?>
Upvotes: 0
Reputation: 2040
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-_]+).domain.com [NC]
RewriteRule (.*) listings.php?category=%2 [NC,QSA]
But if enabled, it don't work, it don't understand the 'category' parameter.
The %2
means to match the second pattern in the RewriteCond
s. In this cae, the second pattern is the ([a-z0-9-_]+)
part.
In my htacces, if mod_rewrite disabled, this works:
If mod_rewrite is truly disabled, then those rules aren't being used.
RewriteRule (.*) http://www.domain.com/%1/listings.html [L]
I'm redirected to the correct page, but I want to keep the subdomain in the browser bar...
If you supply a domain in the RewriteRule, you will always be redirected, you need to supply a path only (like /%1/listings.html
). If the domains are all part of the same VirtualHost, this should not be a problem.
Upvotes: 1