Restrict request uri to sub domain

Using a single web hosting account to host multiple sites

Restrict request uri to sub domain

Postby chrisnetonline » Tue Nov 13, 2007 3:17 pm

I have two subdomains that point to the same code. However I am trying to only allow certain pages to be viewable from one of the sub domains.

This is what I have:
Code: Select all
Options +Followsymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub2(.*)$ [NC]
RewriteCond %{REQUEST_URI} !^/test/?$ [NC]
RewriteRule ^(.*)$ http://sub1.domain.com/ [R,L]
RewriteRule ^/?test/?$ /?view=test [L]


I want to allow http://sub2.domain.com/test but http://sub2.domain.com/test2 should redirect to http://sub1.domain.com/
What seems to happen is I get redirected to http://sub1.domain.com/?view=test when I am visiting a "white listed" page
chrisnetonline
 
Posts: 4
Joined: Tue Nov 13, 2007 2:56 pm

Postby richardk » Tue Nov 13, 2007 3:36 pm

/?view=test matches the first rule.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^sub2\.domain\.com$ [NC]
RewriteRule !^(test/?)?$ http://sub1.domain.com/? [NC,R,L]

RewriteRule ^test/?$ /?view=test [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby chrisnetonline » Tue Nov 13, 2007 3:54 pm

That got me a bit closer to my goal. Is it possible to use that method to add additional white listed urls for the same sub domain? Also, I need to allow css and images files now too.
chrisnetonline
 
Posts: 4
Joined: Tue Nov 13, 2007 2:56 pm

Postby richardk » Tue Nov 13, 2007 4:55 pm

Is it possible to use that method to add additional white listed urls for the same sub domain?

Like what?

I need to allow css and images files now too.

Spread out or in a separate directory (or directories)?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby chrisnetonline » Tue Nov 13, 2007 4:59 pm

Would I be able to do the redirection to sub1 if it doesn't match a list of urls? Like /test/, /blah/, etc...

The css and images are spread out.
chrisnetonline
 
Posts: 4
Joined: Tue Nov 13, 2007 2:56 pm

Postby chrisnetonline » Wed Nov 14, 2007 7:05 am

richardk: with your proposed fix i still seem to be able to get to the base domain (i.e. http://sub2.domain.com/) and any url with parameters in it without a filename (i.e. http://sub2.domain.com/?view=help). however, http://sub2.domain.com/index.php?view=help will redirect.
chrisnetonline
 
Posts: 4
Joined: Tue Nov 13, 2007 2:56 pm

Postby richardk » Wed Nov 14, 2007 12:04 pm

ith your proposed fix i still seem to be able to get to the base domain (i.e. sub2.domain.com/) and any url with parameters in it without a filename (i.e. sub2.domain.com/?view=help). however, http://sub2.domain.com/index.php?view=help will redirect.

It was done to stop it from matching /?view=test and looping. ^(test/?)?$ only matches /, /test and /test/ (not index.php). Query strings are ignored by RewriteRules. It is done differently in the mod_rewrite below.

Would I be able to do the redirection to sub1 if it doesn't match a list of urls? Like /test/, /blah/, etc...

The css and images are spread out.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Ignore CSS, JavaScript and image files (by extension).
RewriteRule \.(css|js|png|bmp|gif|jpe?g)$ - [L]

# Redirect if it doesn't match the list.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^sub2\.domain\.com$ [NC]
RewriteRule !^(the|list|of|urls|test)/?$ http://sub1.domain.com/? [NC,R,L]

# /* to /?view=*
RewriteRule ^(the|list|of|urls|test)/?$ /?view=$1 [L]
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 25 guests

cron