Forum Moderators: phranque
http://website.com/x.php?x=example into example.website.com
I`ll I have managed was this:
rewriteCond $1 !example\.php$
rewriteCond %{HTTP_HOST} ^(.*)\.website\.com [NC]
rewriteRule ^(.*) /example.php?post=$1 [L]
and the page should be like: http://someentryfromsql.website.com/someentryfromsql
I hope it is clear understanding.
The problem is that if I add more lines like if I replace example with example2 for instance I will get an 500 Internal Server Error wich is not good.
I hope I`ll get help here, someone to explain me were i`m doing wrong.
Regards,
Cristian.
[edited by: jdMorgan at 2:19 pm (utc) on May 13, 2008]
[edit reason] de-linked [/edit]
If you want to "map" subdomains to variable "x" and call example.php, then the rule is:
RewriteCond $1 !example\.php$
RewriteCond %{HTTP_HOST} ^([^]+\)\.website\.com [NC]
RewriteRule (.*) /example.php?x=[b]%1[/b] [L]
For example, if you request foo.website.com/bar.html, this rule will rewrite that request to /example.php?x=foo. The "bar.html" is lost.
I suggest you review the function that you are trying to achieve. You cannot write code until the goal is clear.
Jim
RewriteCond $1 !x\.php$
RewriteCond %{HTTP_HOST} ^[^.]+\.y\.com [NC]
RewriteRule (.*) /x.php?post=$1 [L]
works, but if I add another lines:
rewriteCond $1 !z\.php$
rewriteCond %{HTTP_HOST} ^z\.y\.com [NC]
rewriteRule (.*) /z.php [L]
i get 500 internal error for the second page with "z".
and I don`t understand why I get this error.
Because with a "z.y.com" subdomain request, the RewriteCond HTTP_HOST pattern in the first rule will match the output of the second rule, leading to an 'infinite' internal redirection loop, rewriting back and forth between x.php and z.php.
Solution: exclude z.y.com from the first rule explicitly, either by subdomain (RewriteCond %{HTTP_HOST} !^z\.y\.com) or by url (RewriteCond $1 !^z\.php$)
Also, since the second rule is more specific (i.e. it only applies to one subdomain), best practice is to put it first.
When you get a 500-Server Error, your first stop should be the server error log. It will often tell you exactly what is wrong.
Jim