Disallowing Sub Domains.

Using a single web hosting account to host multiple sites

Disallowing Sub Domains.

Postby mynameiszanders » Fri Nov 14, 2008 6:04 pm

Hi there, first post and I'm already asking for help!
If anyone can help me with this I would greatly appreciate it.

My folder structure looks like this:
Code: Select all
public_html / app
            / public / files
                     / otherdirs
            / subd / dirforeachsubdomain


Currently my .htaccess file in public_html re-routes all requests to public_html/index.php, UNLESS it points to a valid file that does not have the extension ".php".

In my .htaccess file in "app", I have it re-routing to public_html/index.php no matter what the request is.
I would like to do the same to "subd" because each folder in there will be a sub-domain, and don't want it accessible from "site.com/subd/folder/"
However, to get that to work, the result of requesting "subdomain.site.com" results in a 500 Internal Server Error!

Any advice that will resolve this problem I will be very grateful for!

Cheers, mniz.
mynameiszanders
 
Posts: 3
Joined: Fri Nov 14, 2008 5:09 pm
Location: England

Postby richardk » Sat Nov 15, 2008 9:25 am

What is your current mod_rewrite?

Try adding the following to /public_html/.htaccess (near the beginning)
Code: Select all
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^subd(/.*)?$ /index.php [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mynameiszanders » Sat Nov 15, 2008 3:52 pm

richardk wrote:What is your current mod_rewrite?

Try adding the following to /public_html/.htaccess (near the beginning)
Code: Select all
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^subd(/.*)?$ /index.php [L]


Brilliant! Works a treat! The only problem is that it won't show a directory listing if the index file is missing, but I'm pretty sure I won't be doing that anyway! If you're still interested my configuration files were:

Code: Select all
"/public_html/.htaccess":

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !\.php$
RewriteRule . /index.php [L]
</IfModule>

"/public_html/subd/.htaccess":

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subd/
RewriteRule . /index.php [L]
</IfModule>

And thanks to you, /public_html/subd/.htaccess no longer exists, and my /public_html/.htaccess now looks like:
Code: Select all
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !\.php$ [NC]
RewriteRule . /index.php [L]

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^subd(/.*)?$ /index.php [L]
</IfModule>

Thanks for all the straight foward help, and for replying so quick! Many thanks, Alexander.
mynameiszanders
 
Posts: 3
Joined: Fri Nov 14, 2008 5:09 pm
Location: England

Postby richardk » Sat Nov 15, 2008 5:21 pm

The only problem is that it won't show a directory listing if the index file is missing, but I'm pretty sure I won't be doing that anyway.

The directory listing of which directory?

If you mean /subd, try replacing
Code: Select all
^subd(/.*)?$

with
Code: Select all
^subd/.+$
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 18 guests

cron