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

  • Home
  • SEARCH
  • 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 3680196
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:32:53+00:00 2026-05-19T03:32:53+00:00

I am working on a new PHP framework for personal use in future projects,

  • 0

I am working on a new PHP framework for personal use in future projects, and
below is my planned file structure so far. I just need some help with some regex for my .htaccess file and some help for how I can load the files I want.

Basically, any “folder” after the domain should load from my “module” folder.
I would like to have it load http://www.domain.com/account/ from http://www.domain.com/module/account/. I also want it in that format for any other folder I have under modules. All folders/files under “module” should load as if it were in the top level.

In this example though in my module/account/ folder, if I have a file called home.php then I should be able to access it with http://www.domain.com/account/home instead of http://www.domain.com/module/account/home.php, and http://www.domain.com/module/user/register.php would actually be accessed by http://www.domain.com/user/register

I hope this makes sense and appreciate any help and any advice. I mainly need help with the .htaccess file to make this folder structure work. I have not decided if all files should be accessed though a single index file or if I should just include a bootstrap type file into every page. The bootstrap file would set up all variables, config options, as well as auto load all class files and create objects needed.

myFramework/
--/assets/
--------/css/
--------/images/
--------/javascript/
--/includes/
---------/classes/
---------/config/
---------/language/
---------/header.php
---------/footer.php
--/module/
--------/account/
----------------/create.php
----------------/login.php
----------------/logout.php
----------------/settings.php
----------------/editprofile.php
--------/admin/
--------/blog/
--------/forums/
--------/messages/
--------/users/
--index.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-19T03:32:54+00:00Added an answer on May 19, 2026 at 3:32 am

    The answer from jasonbar is actually almost there. All it lacks is dealing with the .php extension as you described:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/module
    RewriteCond %{REQUEST_URI} [.]php$
    RewriteRule (.*)[.]php$ /module/$1
    

    That being said, I’d strongly encourage you to consider a front controller paradigm (as you eluded to in your problem description) as doing so allows for much greater control, encourages an MVC approach, etc. =o)

    EDIT:

    I corrected a few neglected points and added proper processing of the PHP extension. Note that the [L] argument at the end causes further processing to cease, making these code blocks useful as logical structures within your .htaccess file (i.e. by preventing any processing that follows); remove that argument if such functionality is not desired.

    I’ve also added a line to specifically check that the php file being requested actually exists.

    RewriteEngine On
    
    # if the uri matches a directory in the module dir, redirect to that. Disable 
    # this block if you don't wish to have either directory browsing or to have the 
    # default apache file load.
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{DOCUMENT_ROOT}/module%{REQUEST_URI} -d
    RewriteCond %{REQUEST_URI} !^/includes
    RewriteCond %{REQUEST_URI} !^/assets
    RewriteCond %{REQUEST_URI} !^/module
    RewriteRule (.*) /module/$1 [L]
    
    # if the uri matches a file sans the .php extension in the module directory, 
    # then redirect to that.
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{DOCUMENT_ROOT}/module%{REQUEST_URI}.php -f
    RewriteCond %{REQUEST_URI} !^/includes
    RewriteCond %{REQUEST_URI} !^/assets
    RewriteCond %{REQUEST_URI} !^/module
    RewriteRule (.*) /module/$1.php [L]
    

    EDIT:

    To also allow files that end in “.php” to be served from the module directory, add the following to your .htaccess file:

    # if the uri matches a file with the .php extension in the module directory, 
    # then redirect to that.
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{DOCUMENT_ROOT}/module%{REQUEST_URI} -f
    RewriteCond %{REQUEST_URI} !^/includes
    RewriteCond %{REQUEST_URI} !^/assets
    RewriteCond %{REQUEST_URI} !^/module
    # note that the following line restricts access to php files only. comment out 
    # the following line to allow any existing file under module director to be 
    # accessed (or modify the following to allow other file extensions to be read)
    RewriteCond %{REQUEST_URI} [.]php$  
    RewriteRule (.*) /module/$1 [L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.