FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Using a single php entry file for a whole site.
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Using a single php entry file for a whole site. [message #181859 is a reply to message #181857] Thu, 20 June 2013 18:18 Go to previous messageGo to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma:
Senior Member
On 20/06/13 18:48, Daniel Pitts wrote:
> On 6/20/13 10:22 AM, The Natural Philosopher wrote:
>>
>> What I would like to do, is the following.
>>
>> ALL request to a site are redirected by apache rules to one single file.
>> Let's call it index.php.
>> Index.php notes the URL the user wants and looks it up in a database,
>> and if it exists, includes() the actual PHP file for that page.
>> If it doesn't exist, a standard 'sorry, you are looking for a page that
>> doesn't exist' is returned, if possible with the correct error code in
>> the headers?
>> The php files themselves apart from index.php do NOT live under the web
>> root. They might in fact live in the database. But that's stage 2.
>>
>> Is this possible, and if so what if any are the downsides?
> This is almost what Symfony2 does. Though its far more sophisticated
> than that as far as how it decides what PHP files to load and to use
> to render the response. It is designed around MVC, rather than
> "Here's a script to render the page."
>
> It has a useful routing mechanism to match URLs and forward to
> appropriate controllers, which then can decide actions to perform and
> views to render.
>
>>
>> It seems to me that a user or robot level scrape of the site would not
>> show anything of its true internal structure. But still show all the
>> paths through it.
>>
>> What I want to do is have stuff like
>>
>> http:/mysite.com/news/Dog-Bites-Man
>>
>> redirect to say
>>
>> /var/private/newspage.php?id=3041
>>
>> where there exists a mysql table with a name value pair of
>>
>> news/Dog-Bites-Man: /var/private/newspage.php?id=3041
>> or
>> menu/Contact-the-webmaster: /var/private/contact.php?target=webmaster
>>
>> and so on.
> What I've seen is that the web-server (nginx in my case, but Apache
> should work too) forwards (not redirects) the request to exactly one
> script "/path/to/my/site/web/index.php", which then does all the logic
> for deciding the routes. Once that is determined, all the logic to
> render that specific page is executed, and then the view is presented.
>>
>> And possible a field for keywords to search the site with.
> Very doable.
>
> Hope this helps,
> Daniel.
>

It did a lot actually. in the time between posting and reading your
reply I have stumbled through the rewrite rules on apache and proved
the basic stuff will in fact work. (after redirecting more than I
bargained for)!
In short everything except two directories and various image types now
gets redirected to /index.php.

What I had to in debian was (as root)

# a2enmod rewrite

then restart the server

and then edit the apache2 config file for the domain like this

RewriteEngine on
RewriteRule ^(admin|downloads)($|/) - [L] # allows normal access to the
admin and downloads dirs
RewriteRule !^(index.php)|.(js|ico|gif|jpg|png|css|mp3|xml|swf)$
/index.php [L] # shoves everything else to index.php except index.php
itself and anything ending with the listed extensions.

NOW I have to build the intelligence..back in PHP land.

I've got two $_SERVER variables that seem to hold the info I want.

One is ["REQUEST_URI"] and the other is ["REDIRECT_URL"]

any reason to prefer one over the other?

>
>


--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Updating old PHP code
Next Topic: Komodo Edit
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 01:54:27 GMT 2024

Total time taken to generate the page: 0.05978 seconds