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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:25:04+00:00 2026-05-29T05:25:04+00:00

So far I’ve done this: RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule

  • 0

So far I’ve done this:

RewriteBase /
RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond  %{REQUEST_FILENAME} !-d
RewriteRule  ^(.*)$ index.php?load=$1 [QSA,L]

Then on my index page (in the root directory) I’m using PHP to determine which page to load:

// Swap to variables
    $load = $_GET['load'];

// Home page
    if (!$load || $load == "") { include('home.php'); exit(); }

// Dashboard
    if ($load == "dashboard") { include('dashboard.php'); exit(); }

// About
    if ($load == "about") { include('about.php'); exit(); }

// Username
    $data_array = array(':username' => $load);
    $select_account = $connect->prepare("SELECT * FROM `users` WHERE `username` = :username");
    $select_account-> execute($data_array);
    $account_amount = $select_account->rowCount();
    if ($account_amount > 0) { include('profile.php?name=$load'); exit(); }

// Redirect to 404 if there are no results
    include('404.php'); exit();

Everything so far is working but users can upload photos to a gallery and I want them to be viewed like so:

www.mysite.com/[username]/gallery/

But if you were to type that as the url the rewrite reads [username]/gallery/ as one section which means $load = [username]/gallery which would give me a ‘404’.

There is probably a better solution to getting the desired results but I’m not too good with the .htaccess and rewriting. I would like to add that I like this rewrite too since I have sub-directories called signup and signin which both have sub-directories in them too, but if I go to the URL:

www.mysite.com/signup
www.mysite.com/signin

It ignores the rewrite and goes to the directory instead of running it through the $load statements which is what I want.

Also, to note, on registering an account, any username which matches strings such as dashboard or about etc it doesn’t allow them to use it, this stops usernames and the $load if/else statements and their includes being mixed up etc

EDIT

Another thing I forgot to note is since they can call the gallery whatever they like, it needs to do a search to see if that gallery exists, so for example:

www.mysite.com/username/my+first+album

It would first need to check the username exists, then check the album exists, then display it if it does or 404/redirect to wherever if it doesn’t. So basically, both parameters/queries will be dynamic. Not only that but then individual photos within that album need to work the same, for example:

www.mysite.com/username/my+first+album/my+picture

I hope that makes sense…

  • 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-29T05:25:05+00:00Added an answer on May 29, 2026 at 5:25 am

    With help from both Aatch and Sally and a few search results on URL routing, I’ve got the following method to achieve what I was after so I thought I’d share it with everyone in case anybody might want to use it…

    First of all I need to mention the site I’m working on is within 2 sub-directories of the root folder mysite.com/sub/folder/index.php hence why on the arrays I’m starting from [3]

    With that said my .htaccess file is as followed:

    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . sub/folder/index.php [QSA,L]
    

    This, as far as I’m away, gets anything that is written after sub/folder/ and redirects the page straight back to the index.php, however, it masks the URL in the address bar.

    The only time it ignores this is if the sub directory actually exists. So for example I have a folder /sub/folder/signup/ if I was to type that in the address bar, because the directory exists then you are not redirected to the index.php file but sent to the directory requested, just like normal.

    Now on my index.php file (Remember I’m starting at $uri[3] because I’m in sub folders!)

    $uri = $_SERVER['REQUEST_URI']; // This brings back /sub/folder/foo/bar/test/
    $uri = explode("/", $uri); // Separate each one
    
    $var_one = $uri[3]; // foo
    $var_two = $uri[4]; // bar
    $var_three = $uri[5]; // test
    
    switch ($var_one) {
    
        case '':
        case 'home':
            include('home.php');
            exit();
            break;
    
        case 'signout':
        case 'logout':
            include('signout.php');
            exit();
            break;
    
        case 'dashboard':
        case 'dash':
            include('dashboard.php');
            exit();
        break;
    
    }
    
    // By Username
        $data_array = array(':username' => $var_one);
        $select_account = $connect->prepare("SELECT * FROM `users` WHERE `username` = :username");
        $select_account -> execute($data_array);
        $account_amount = $select_account->rowCount();
        if ($account_amount > 0) { include('profile.php'); exit(); }
    
    // By Account ID
        $data_array = array(':id' => $var_one);
        $select_account = $connect->prepare("SELECT * FROM `users` WHERE `id` = :id");
        $select_account -> execute($data_array);
        $account_amount = $select_account->rowCount();
        if ($account_amount > 0) { include('profile.php'); exit(); }
    
    include('page_not_found.php');
    

    The switch cases are simple includes, if the url is: /sub/folder/dashboard/ then dashboard.php is shown. If none of the cases match then we could possibly be looking at a profile. The first checks to see if it could be a username, if it exists then the view profile page is displayed. Then, it checks to see if it could be the unique ID number for that profile and does the same check.

    Finally, if no results are brought back from any of them, then we are shown a 404 page not found page.

    If it was a profile page, on the profile.php file I can then run checks for $var_two and see if they have uploaded a photo album under that name, for example /sub/folder/joe/holiday/ if yes, then run a query to fetch it all, if not, display a message/redirect or whatever.

    Then if there is even more, say a specific picture ($var_three) in that folder ($var_two), for example /sub/folder/joe/holiday/beach/ – then run it through a similar query showing the results.

    It may not be the best method but it’s pretty straight forward and everything is working as I’d like it too so I can’t really complain.

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

Sidebar

Related Questions

As far as I can tell, this is isn't possible, so I'm really just
so far, I have this: class Foo{ private $plugin_methods = array(); public function registerPlugin($caller,
this is what i have right now Drawing an RSS feed into the php,
So far i wrote a code to download a file from ftp server then
As far as I can tell this is perfectly valid batch-file code, just a
So far all the sites I have made have been in PHP, I'm thinking
So far I know two ways to pass php variables to javascript. One is
As far as I know this isn't possible. I would like to draw an
So far i got this code: function toplist() {$sql = SELECT * FROM list
So far I'm working on a HTML file like this <div name=node></div> <div></div> <div

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.