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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:38:36+00:00 2026-06-08T09:38:36+00:00

I have a self-built MVC fw with a router routing URLs such that the

  • 0

I have a self-built MVC fw with a router routing URLs such that the common example.com/controller/action is used. I’m running into issues when my application is deployed within a sub-directory such as

example.com/my_app/controller/action/?var=value

My router thinks my_app is the name of the controller now and controller is the method.

My current solution is to manually ask for any sub directory name in a config at install. I’d like to do this manually. See my question below and let me know if I’m going about solving this the wrong way and asking the wrong question.

My question:
if I have two paths, how do I truncate the common pieces from the end of one and remove it from the end of the other.

A = /var/www/my_app/pub
B = /my_app/pub/cntrl/actn

What’s your quickest one liner to remove /my_app/pub from B and remain with /cntrl/actn?
Basically looking for a perl-esque way of getting the common denominator like string.

Thanks for any input

  • 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-08T09:38:39+00:00Added an answer on June 8, 2026 at 9:38 am

    The way I would solve this is adding this logic to the front controller (the file to which your server sends all nonexistant file requests, usually index.php).

    $fontControllerPath = $_SERVER['SCRIPT_NAME'];
    $frontControllerPathLength = strlen($fontControllerPath);
    
    $frontControllerFileName = basename($fontControllerPath);
    $frontControllerFileNameLength = strlen($frontControllerFileName);
    
    $subdirectoryLength = $frontControllerPathLength - $frontControllerFileNameLength;
    
    $url = substr($_SERVER['REQUEST_URI'], $subdirectoryLength - 1);
    

    Here’s a codepad demo.

    What does this do? If the front controller is located (relative to the www root) in: /subdir/myapp/, then it’s $_SERVER['SCRIPT_NAME'] would be /subdir/myapp/index.php. The actual request URI is contained in $_SERVER['REQUEST_URI']. Let’s say, for example, that it is /subdir/myapp/controller/action?extras=stuff. To remove the subdirectory prefix we need to find the length of it. That is found by subtracting the length of the script name (retrieved from basename()) from the length of the script’s name relative to the www root.

    File that receives request: /subdir/myapp/index.php (length = 23)
    Filename: index.php                                 (length = 9)
                                                                     -
    -------------------------------------------------------------------
                                                   14 chars to remove
    
    /subdir/mpapp/controller/action?extras=stuff
                  ^
                  Cut off everything before here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C++03 I used pthread with a self-built thread pool that always kept a
I have built a webservice into my companies self developed CRM system that we
I have built this query that is kind of self explanatory: SELECT events.*,(SELECT COUNT(*)
I have seen the railscast on self-referential relationships here: http://railscasts.com/episodes/163-self-referential-association I have built upon
I have an app that is built starting from a tab bar controller. It's
I have a self-referential table in my database that looks sort of like above.
I have a self referencing table named categories that has a parentcategoryid column that
I have a self referencing table in Oracle 9i, and a view that gets
I have dictionary that is built as part of the initialization of my object.
I have a query that is very recently starting to throw: The built-in indices

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.