Welcome to WebmasterWorld Guest from 184.108.40.206
I have created a site based on a template, I do not know the correct term to cover this so I will explain how it works:
I have one php page (index.php) which includes the relevant page when a user clicks on a link i.e. the url may look like '<site url>/index.php?page=news' so this includes the content from the file news into the index page.
What I would like to know is what is the best way to prevent a vistior to the site just going to '<site url>/news'. I would like to detect if the page was called directly and if so redirect them back to the home page.
I hope this makes sense.
Any help appreciated.
I can say that in my aff sites, if a particular producer will not allow me to link directly to a product page, using a redirect as you would like to do, they are usally dropped from my selling efforts. I can also say, if I clicked on a link with specific link text, especially if it were a serp, and it went to a general topic home page I would likely leave.
Many here really dislike a deep linking (as it is sometimes called) to an internal page but I disagree because it's what's best for me, the surfer, not because it's best for you or the owner. IMHO
Imagine if I had to go to the CNN home page everytime I wanted the CNN Sports page...
If I were to let direct access to each page then I would need to include all the menu code in to each page (so each page would be rendered in full - i.e. to make it look the same as if the visitor choose <site url>/index.php?page=news)and this would negate the use of templates as each page would become cluttered and not so easy to just add content. I am new to web design so I may have got the whole thing worng - I am open to suggestions.
I think that's probably the most common solution around. That's how I handle (most of) my header and footers. For a dynamic template that might produce 1000's of pages it's a matter of adding a few lines of code to the template.
I really appreciate all the input I have received on this, thanks for bearing with my ignorance.
I don't know PHP, so I can't offer you code, but the principle should be clear:
- On index.php set a session variable at the very beginning of the page. The session variable could be the name of the file you're including, i.e. products.php.
- On the included page, i.e. products.php, put an If statement around the whole page to check if the session variable is set to the name of the included page, i.e. products.php. If it is, the page is "executed", if not, it's not and a redirect is issued.
Also, instead of redirecting to a general page, why not point straight to the "proper" page loaded via index.php, i.e. index.php?thepage=products.php. That way people would see what they were looking for using the template you set up.