News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Force Forum access from Website

Started by Frobisher, August 13, 2014, 12:02:04 PM

Previous topic - Next topic

Frobisher

I have the following structure on my Web Server. By structure I mean directories.

html_public
forum
site_1
site_2

Both site_1 and site _2 have their own navigation menus and only want to allow access from site_1 and site_2.
If I were to use an htaccess redirect in the forum directory, then I would produce a loop.

What I want to deny is access from www.domain/forum - Hope that makes sense.

Can someone help me with how I can solve this.

Thank you.
Windows 10 | SMF 2.0.13

kat

How about a php redirect?

<?php
function Redirect($url$permanent false)
{
    if (
headers_sent() === false)
    {
    
header('Location: http:www.domain/forum/index.php' $urltrue, ($permanent === true) ? 301 302);
    }

    exit();
}
?>



I *think* that's right...

Frobisher

Trying to understand the logic in that php code to see if it will accomplish the desired result.
Also, where would that php code be placed?

Thanks.
Windows 10 | SMF 2.0.13

kat

You'd need to put that as index.php, in the root of the directory that holds http://www.domain.com

This'll explain things far better than I could. :)

http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php

Arantor

So the user is supposed to go to site_1 or site_2 and you include the forum from there or you redirect or what?

If you're hoping to do a redirect of any kind to the forum directory, you absolutely cannot prevent people going directly to the forum since you can't rely on referers being set correctly.

Kindred

Basically, as Arantor says... It just won't work.  If you want them to use the forum, you can not prevent them from accessing the forum. Period.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Frobisher

Thank you for your replies.

Many years ago when I managed another website I had a tiny piece of javascript code that only allowed access via the home/index page. This prevent users going directly to other pages and bypassing the home page.

Let me explain what I am attempting to do.

User attempts to access http://www.domain/forum/index.php ... force this to one of the following

http://www.domain/site_1/index.htm ... site_1 is a directory containing all of the files for website 1

or

http://www.domain/site_2/index.htm ... site_2 is a directory containing all of the files for website 2

Both of those websites have a menu link which goes to,

http://www.domain/forum/index.php

So, the user can only access the forum from either website 1 or website 2.

If it cannot be done, then I will have to live with it.

Thanks again.
Windows 10 | SMF 2.0.13

Hj Ahmad Rasyid Hj Ismail

That is supposedly URL redirect from root to sub folder, right? It won't work on all hosts. But normally the host will provide a how to if they allowed that. They may even help if you ask for support if they do allow it. But normally you have to choose only one redirection for it. Other sub directory can be handle via other domain or sub domain.

Frobisher

Thanks ahrasis for your reply.

I cannot get to root on my Web Server - not allowed. The top level is html_public. So, what I am attempting is a redirect from directory forum to directory site_1. From site_1 there is a menu link to forum.

It all appears to be very complicated or impossible so I about to give up on this mission.

Thanks to all.
Windows 10 | SMF 2.0.13

Arantor

In which case it is not possible to reliably do what you are hoping without a serious rewrite of the SMF session system and I could not recommend that to anyone (since you're essentially then mandating the session begin outside SMF, which while technically possible is such a ridiculous waste of effort to actually do properly, it's not worth it)

Hj Ahmad Rasyid Hj Ismail

#10
Sorry I get you wrongly.

Edited: Install your site_1 folder. Place this code in .htaccess file in your forum folder:
RewriteEngine on
RewriteRule ^forum/(.*)$ /site_1/$1 [R=301,NC,L]

Frobisher

Killer Ninja Coding Monkey - I am not mandating anything. If you believe what I am attempting to do is not sensibly possible, then that is understood.

ahrasis - Your suggestion of using htaccess was what I was going to attempt but I believed it will cause and endless loop. I will give it a try nevertheless.

Thank you both.
Windows 10 | SMF 2.0.13

Kindred

That will cause a loop.

As you have already been told, you can not do what you are asking to do.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Hj Ahmad Rasyid Hj Ismail

Based on his answer in reply #6, I don't think it will cause any loop, at all. Having a menu with link to forum folder is useless though.

Arantor


Kindred

Aharis,

You must have misread his reply then...   Because  he wants people from site1 and site2 index.htm files to access the forum, using the from link.
He just does not want people to be able to access the forum without first hitting one of the index.htm locations.

In other words, they should get to forum/index.php just fine, if and only if they passed through site1/index.htm or site2/index.htm first.


And, as Arantor an I both said...   It won't work.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Frobisher

Kindred, That is precisely what I am attempting to do. You and others have said it will not work. Let's close this thread rather than waste more time.

Thanks for taking the time.
Windows 10 | SMF 2.0.13

Hj Ahmad Rasyid Hj Ismail

Oh my, I am confused even further. Listening back, Kindred is right. One can only access site_1 folder or site_2 folder with no access to forum folder once he rewrited and redirected it to any of them. One cannot redirect and come back to it if that is the whole point OP was asking.

Rewrite and redirect that I have suggested will totally deny any access to forum folder by any way by allowing the user to use only forum in site_1 and forum in site_2.

I mean access to only forum in site_1 and/or forum in site_2
Quote from: Frobisher on August 14, 2014, 02:30:49 AM
So, the user can only access the forum from either website 1 or website 2.

and not the forum folder itself as what the OP said in the first place
Quote from: Frobisher on August 13, 2014, 12:02:04 PM
What I want to deny is access from www.domain/forum - Hope that makes sense.

that's why I said:
Quote from: ahrasis on August 14, 2014, 08:26:23 AM
Based on his answer in reply #6, I don't think it will cause any loop, at all. Having a menu with link to forum folder is useless though.

I should stop now. So sorry for any misunderstandings and any inconveniences.

Arantor

Though I would ask: what point is there to having a single forum shared between 'two sites'? Why not one site and be done with it?

I'm curious because there may be a better way to solve the problem you think you have, but without further information it's impossible to say.

Sir Osis of Liver

Actually, there is a way to redirect www.domain/forum to one of the websites without creating a loop or breaking the forum, but it only works when that exact url is used, and does not prevent users from bookmarking the forum once they get there.  Don't imagine that would accomplish what OP wants.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Advertisement: