Forum Moderators: phranque

Message Too Old, No Replies

Rewrite, Subdomains, and Wildcard Alias

blog and forum in same directory, need different default page for each one

         

Protoavis

5:39 pm on Apr 16, 2006 (gmt 0)

10+ Year Member



What I am trying to do is get www.example.com to go to www.example.com/index1.php by default, and subdomain.example.com to go to subdomain.example.com/index2.php by default.

I am using a wildcard alias for the subdomains, and the according changes have been made to the server config and dns. So all files are in the same directory. This is working fine.

So far I have the htaccess working, mostly. www.example.com and example.com go to the index1.php and works perfectly. subdomain.example.com goes to index2.php like it is supposed to as well.

The problem that I am having is that any time I try to go to subdomain.example.com/anything_other_than_index2.php, I get a 404 error.

I am missing something in my htaccess file to make it all work, but I have no idea what that is. As you can see, Index1.php is my default index, since I do not have a index.html or index.htm.


DirectoryIndex index.html index.htm index1.php index.php

Options -Indexes
Options +FollowSymlinks

<IfModule mod_rewrite.c>
RewriteEngine On

#Code for changing default index for subdomains
#No change for www.example.com - go to normal index1.php
RewriteCond %{HTTP_HOST}!^www\.example\.com [NC]
#Take effect for subdomain.example.com
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
#Where I am having issues...
RewriteCond %{REQUEST_URI}!^/index2.php [NC]
#Pull up index2.php for subdomain instead of default index1.php
RewriteRule (.*) /index2.php$1 [L]

So I think the issues are with the line: RewriteCond %{REQUEST_URI}!^/index2.php [NC]
If I change it to!^/(.*), I no longer get 404 errors, but my subdomains no longer go to index2.php either.

The logic needs to work like this: If you are using a subdomain and trying to go to default index1.php, go to index2.php as default instead. If you are using a subdomain and trying to go to any file except index1.php or index2.php, allow all other files to come through with no change.

But as the code is, when using a subdomain and trying to access anything other than index2.php (IE subdomain.example.com/blah.php), I get a 404 error. Keep in mind all of my files are in the same directory, as I am using a wildcard in the config and dns.

Please help. I have put hours and hours into this and have got this far on reading tons and trial and error. Thank you and Happy Easter!

jdMorgan

1:11 pm on Apr 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



From your own verbal description of how this should work, "trying to go to default index1.php, go to index2.php," you need to change the rule to:

RewriteRule ^index1\.php$ /index2.php$1 [L]

Jim

Protoavis

10:38 pm on Apr 17, 2006 (gmt 0)

10+ Year Member



I tried this once before, but that was before I learned about conditions and it didn't work right, and it didn't dawn on me to try it again after finally getting the conditions correct...

Thanks so much! Works like a charm now!