Forum Moderators: phranque

Message Too Old, No Replies

Subdomain to variable

How to redirect subdomain 2 variable

         

yotam

11:32 am on May 27, 2006 (gmt 0)

10+ Year Member



Hi,

I'm trying to redirect (virtual) subdomains to variables as follows :

Options +FollowSymlinks
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\domain\.com [NC]
RewriteRule ^(.*) /index.php?page=%1 [L]

But it doesn't work!
Can anyone PLEASE tell me what's wrong with my code?

I use Apache 1.3.34

yotam

11:34 am on May 27, 2006 (gmt 0)

10+ Year Member



Oops,

I typed it wrong last post

RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com [NC]

Well, what's wrong?

jdMorgan

2:40 pm on May 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks like it would create a loop. You should exclude "index.php" from being rewritten. The check for a blank hostname is not needed, either, since your third RewriteCond requires a hostname with subdomain to be present. And a few more minor clean-ups:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
#
RewriteCond $1 !^index\.php$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com [NC]
RewriteRule (.*) /index.php?page=%1 [L]

I assume you handle the requested page name within the script itself, since as written, your variable "page" will actually contain the subdomain name, not the page name.

Jim

yotam

12:36 pm on May 29, 2006 (gmt 0)

10+ Year Member



Hi Morgan,

Well man it doesn't work and I can't see anything in the logs :-(

How can I analyze it?
Th's is why sometimes developing is so sucks!

jdMorgan

8:28 pm on May 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1) Use the Apache mod_rewrite documentation [httpd.apache.org] to amalyze and fully understand the code. Make sure it suits your application.
2) Change the rule (temporarily) to an external redirect, so you can see the rewrite results in the address bar:

RewriteRule (.*) http://www.example.com/index.php?page=%1 [R=302,L]

As I stated, I don't know what you intend to do with the requested page name, since your original code dropped it, and my fix-up code does as well. I assume that your script will access the REQUEST_URI server variable (or similar) to get it, but I can't be sure, since you didn't address that point.

Jim

yotam

11:06 pm on May 29, 2006 (gmt 0)

10+ Year Member



Hi jdMorgan,

Well, I want to redirect virual subdomains to index.php as variable, and that is only the begining, after that I will have to redirect folders to variables, but this as well should be easy.

Well, I try the [R=302,L] and see what request I get in the URI.

Thanks or now :-)

yotam

11:55 pm on May 29, 2006 (gmt 0)

10+ Year Member



Hi,

First of all 10x for everything.

Well it works if I have a real subdomain, but not for virtual ones, so I guess I have a deny from other rules? Is it possible?
Well, maybe in httpd?

10x,
Yotam