Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3755252
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:40:12+00:00 2026-05-19T09:40:12+00:00

I am working on a good solution for routing and including the correct pages

  • 0

I am working on a good solution for routing and including the correct pages in a social network type project I am working on. I have decided to run all my routing through a single entry point file. I do not wish to use an existing framework for this. If you review the sample code below you can see that it is pretty basic and should be good on performance for a high traffic site except I am stuck when it comes to modules that require paging. the whole point of this is to have clean looking URL’s everywhere on the site.

So please help me with modifying to work with paging when there is a paging number in the URL.

(ie; domain.com/blogs/comments/234)

.htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$   test.php?uri=$1    [NC,L,QSA]

test.php file

<?PHP

//get url from URL
$uri = isset( $_GET['uri'] ) ? $_GET['uri'] : null;

// Array of possible pages to include
$pageId = array( 
                'account' => 'modules/account/index.php',
                'account/create' => 'modules/account/create.php',
                'account/settings' => 'modules/account/settings.php',
                'account/login' => 'modules/account/login.php',
                //example of a URL which will need paging....
                'users/online/' => 'modules/users/online.php',
                'users/online/12' => 'modules/users/online.php?page=12'  // not sure if including a page like this is even possible?
                );

// If $_GET['uri'] exist and there is a valid key/value for it in the $pageId array then include the file
if( $uri !== null ) {
    if (isset($pageId[$uri])) {
        require_once $pageId[$uri];
    }
    else {
        require_once 'home.php';
    }
}
else {
    require_once 'home.php';
}

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T09:40:12+00:00Added an answer on May 19, 2026 at 9:40 am

    I think you are doing some premature optimization here. Take a look at this discussion on quora about configuring apache for high traffic websites. I think it might help you.

    http://www.quora.com/What-is-the-best-apache-conf-configuration-for-a-webserver-whose-handle-100-request-per-second-with-PHP-APC-enabled-and-htaccess-image-compression?q=requests+per+secont

    Apart from that you should probably change the semantics of you $pageId array from key -> page as it is today to a regex -> replacement array.

    Something similar to this:

    $pageId = array( 
                    'account' => 'modules/account/index.php',
                    'account/create' => 'modules/account/create.php',
                    'account/settings' => 'modules/account/settings.php',
                    'account/login' => 'modules/account/login.php',
                    //example of a URL which will need paging....
                    'users/online/' => 'modules/users/online.php',
                    'users/online/(\d+)' => 'modules/users/online.php?page=$1'
                    );
    

    And in your routing code you should iterate the array build a regular expression and match the url. When it matches you should do the replacement and you get the page to invoke. However if this is done straight forward it will kill your routing performance :(. A lot of frameworks do this already pretty well from that i know and i think you should try to take a look in there to see what you can borrow :).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a dynamic php web page localhost/ctd/index.php All working good except if i
Good afternoon, I'm working on a project for my company to run an update
I have been looking for a good solution all day, but Google evolves so
I'm still working on a good solution to my One-Of-A-Type Container Problem -- and
Good day. Has somebody working solution for deleting asset in nested form in Carrierwave?
I have defined keyboard events which is working good in desktop but for touch
I have created jquery image slider and it is working good. However i have
Okay, I've looked all over the internet for a good solution to get PHP
I've recently begun working in Sproutcore, which seems to be a really good solution
I'm working on making some code using metaheuristics for finding good solutions to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.