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 8108375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:05:26+00:00 2026-06-06T01:05:26+00:00

Using .htaccess all addresses are rewritten to index.php Index.php needs to then work out

  • 0

Using .htaccess all addresses are rewritten to index.php

Index.php needs to then work out which file to include. At the moment it explodes on the ‘/’ and performs a foreach to work out which file. This is causing errors.

First we get the URI.

If there is one address eg. localhost/next-page then we want to include a file with that name and the extension PHP include('content/'.$post.'.php'); and give global variables for $table as 'PAGES' and $post as 'next-page'

If there are two then the first should be considered the $table and the second the $post, and the file to include should be include('content/single-'.$post.'.php');

How do we do this?

  • 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-06-06T01:05:29+00:00Added an answer on June 6, 2026 at 1:05 am

    First you need to isolate the relevant part of the URL (in this case that’s probably the path, although without your rewrite rule we don’t know). Then:

    $parts = explode('/', $path);
    switch(count($parts)) {
        case 1:
            // set your globals (why are you using globals????)
            include('content/'.$parts[0].'.php');
            break;
        case 2:
            // do whatever you need with $parts[0] and $parts[1]
            break;
        // etc
    }
    

    If there’s significant similarity between some cases, you can allow a fall-through from one case to the next after doing some preliminary work to normalize the situation, e.g.

        case 1:
            array_unshift($parts, 'PAGES'); // now $parts will have two elements
            // intentional fall-through
        case 2:
            // do whatever you need with $parts[0] and $parts[1]
            break;
    

    Finally: if there’s lots of stuff you need to do with the items inside $parts, you can give them names to make the code more readable using the list construct:

        case 2:
            list($table, $post) = $parts;
            // carry on as before but now $table == $parts[0] and $post == $parts[1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the moment using .htaccess in my PHP Application to choose which page I'm
I would like to redirect all images to a showimage.php, using htaccess But if
Is it possible to deny from all apache htaccess style using php. I can't
I'm trying to filter all clients (using .htaccess) who try to access addresses containing
I am using the following .htaccess rule to redirect all pages of my site
I want to redirect using .htaccess abc.com/test.php to abc.com/test . but it will execute/display
I am trying to redirect /folder to / using .htaccess but all am I
Possible Duplicate: Redirect *.htm to *.php htaccess rewrite if redirected file exists I set
Using a redirect statement in my htaccess file, people who type the following into
I am using htaccess in my site, such that all the request to my

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.