Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite & subdomain question

rewriting subdirectory of subdomain to primary

         

Philosopher

10:31 pm on Mar 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok...after MUCH work last evening I was able to get all calls to subdomains to be rewritten to the same primary URL

Here's what I have

ex. - [subdomain.example.com...] gets rewritten to

[example.com...]

Perfect working like a charm...now for the problem

I need to also rewrite

[subdomain.example.com...]

to

[example.com...]

Nope...not happening.

I've tried a number of different things in htaccess but none of them are working properly.

When I try

RewriteCond %{HTTP_HOST}!^www\.example.net [NC]
RewriteCond %{HTTP_HOST}!^example\.net [NC]
RewriteRule ^(.+) %{HTTP_HOST}/$1 [C]
RewriteRule ^(.+)\.example\.net/(.*) index.php?c=$1&s=$2 [L]

For some reason variable $2 gets set with "index.php" instead of the subdirectory even though the URL is in the form of [subdomain.example.com...]

Any help would be greatly appreciated.

closed

4:45 am on Mar 12, 2004 (gmt 0)

10+ Year Member



You could just examine REQUEST_URI in a RewriteCond. It looks a lot clearer that way (to me, at least).

Also, could it be that the problem is that you're using

example.net
in your code instead of
example.com
?

Philosopher

10:01 pm on Mar 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmm...you wouldn't happen to have an example would you? I've tried a couple of things and haven't been able to get them to work.

As for the .com/.net thing, it is a .net site. The example.com was just a generalized example url so no that's not it.

Anyone else have any ideas? I've spent pretty much the last 24 hours stuck on this one thing and it's starting to p*ss me off. ;)

closed

5:40 am on Mar 13, 2004 (gmt 0)

10+ Year Member



Pseudo-code for your first case:
If HTTP_HOST is
subdomain.example.com
, and REQUEST_URI is not the directory index of the subdomain, rewrite the address to
http://www.example.com/index.php?c=subdomain
.

I'd probably use a regex like this to check if REQUEST_URI is a directory index (assuming index.html is the filename): (¦/¦/index\.html)

Pseudo-code for your second case:
If HTTP_HOST is

subdomain.example.com
, and REQUEST_URI is a subdirectory, rewrite the address to
http://www.example.com/index.php?c=subdomain&s=subdirectory
.

When you check for existence of the subdirectory, obviously you wouldn't use -d in your RewriteCond; you'd just need to check that it's not a directory index.