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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:01:38+00:00 2026-05-28T04:01:38+00:00

My goal is to get everything after the domain name into a string. As

  • 0

My goal is to get everything after the domain name into a string. As in mysite.com/page/page2 would result in a string “page/page2”. That I can do, however it starts giving me problems when, for example, the site is in a subfolder and not in root, then the folder the site is in will also be included in the string and if I’m not using mod_rewrite to get pretty links, it will also add index.php to the string.

So, I would need a trick or two to make the script understand whether or not the site is in a subfolder such as mysite.com/sitefolder/page/page2 and that it would still result in a string

page/page2

If the site doesn not use mod_rewrite and the url is mysite.com/sitefolder/index.php/page/page2, it would still result in a string

page/page2

Keep in mind that I have URL and USE_MOD_REWRITE defined in a config file, so no need for magic. I just have no idea how to go about getting that string. I know I could do $_SERVER[‘REQUEST_URI’] to get the string, but then index.php would still be in it. I’m sorry if I didn’t explain well enough, but all help is appreciated.

  • 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-28T04:01:38+00:00Added an answer on May 28, 2026 at 4:01 am
    • get the path by parsing the request uri
    • remove eventual script name from the end of the string (e.g. index.php)
    • rtrim any trailing slashes

      $request = parse_url($_SERVER['REQUEST_URI']);
      $path = $request["path"];
      $result = rtrim(str_replace(basename($_SERVER['SCRIPT_NAME']), '', $path), '/');
      

    EDIT

    $request = parse_url($_SERVER['REQUEST_URI']);
    $path = $request["path"];
    
    $result = trim(str_replace(basename($_SERVER['SCRIPT_NAME']), '', $path), '/');
    
    $result = explode('/', $result);
    $max_level = 2;
    while ($max_level < count($result)) {
        unset($result[0]);
    }
    $result = '/'.implode('/', $result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My goal is to match the first 0 and everything after that zero in
I have problem that im trying to get solve for like week. My goal
my goal is to get lots of rows from a translation table. I use
My goal is to get various SEO-relevant information for various sites. Basically all the
I am trying to get my head around a LINQ issue. The ultimate goal
goal: I have the string 1234432144 I want to only replace the first 2
My Goal I would like to have a main processing thread (non GUI), and
The goal I need to achieve is to get all records from a cursor
I'm trying to pass in a Base64 string into a C#.Net web application via
Using reflection you can get pretty much everything relating to a class. You can

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.