Forum Moderators: phranque

Message Too Old, No Replies

Keep users on forum site, if not, send them to home site

Using .htaccess to keep users on forum subdomain's forum page

         

MickeyRoush

10:38 pm on May 11, 2012 (gmt 0)

10+ Year Member



I've got a forum site that looks exactly like the main site. I want to keep users from browsing the forum site except for the forums and if they try to venture off the beaten path they are sent to the main site or possibly back to the forum site's main forum page.

Main site: example.com
Forum site: subdomain.example.com/forums/

I have a menu button on the main site (example.com) that when clicked, sends them to: subdomain.example.com/forums/

I've tried this in the subdomain's .htaccess and it doesn't seem to work. I've used something similar for use with an iframe, so I thought it might work in this situation. I tried incorporating the subdomain.example.com/forums/ into the mix, but I kept getting a redirect loop.

All this below does is redirect the user back to the main site when they click the forum menu button on the main site, so they can't access the forums. I believe I need some type of exception for the subdomain, but I've tried incorporating that as well and it didn't work either.

RewriteCond %{HTTP_REFERER} !^https?://(.+\.)?example\.com/ [NC]
RewriteRule .* http://example.com/$1 [R=301,L]


I've also experimenting using REQUEST_URI and got the same unwanted result.


Any suggestions/help would be greatly appreciated.

g1smd

10:48 pm on May 11, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You should be looking at what URL is requested, not at what the referrer is. Referrer data is unreliable and often missing.

So, if request is for NOT /forum
redirect page request to main domain.

Sounds like two lines of code will fix that.

MickeyRoush

12:03 am on May 12, 2012 (gmt 0)

10+ Year Member



I tried using:

RewriteCond %{REQUEST_URI} !http://subdomain\.example\.com/forums/ [NC]
RewriteRule .* http://example.com/$1 [R=301,L]


I also tried using RewriteCond %{THE_REQUEST} in place of RewriteCond %{REQUEST_URI} and I still couldn't get it to work. I know it must be something little that I'm overlooking.

lucy24

2:53 am on May 12, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



REQUEST_URI definitely won't work, because that's just the "body" of the URL, neither the host nor the query. Why don't you simply look at HTTP_HOST (not to be confused with REMOTE_HOST)?

I suppose it would be idle to ask why you even have the pages if you don't want people to go to them...

MickeyRoush

10:07 am on May 12, 2012 (gmt 0)

10+ Year Member



@ lucy24

I suppose it would be idle to ask why you even have the pages if you don't want people to go to them...


There's a conflict where I couldn't incorporate the forums within the main site. So I just made the forums look exactly like the main site on a subdomain. The only thing they need to access is the forums on the subdomain, so I don't want anyone trying to browse anything there except the forums.

I'll try your recommendation and report back. Thanks.