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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:29:01+00:00 2026-06-09T15:29:01+00:00

I have a configuration file. This is not a stand-alone file. I will be

  • 0

I have a configuration file. This is not a stand-alone file. I will be including this file at the top of the pages that I want to use in, using require(). I want to dynamically get the complete absolute url path to this configuration file, regardless of it’s location and store it as a constant within itself. For example:

Physical Location: (root dir)/my_folder/configuration.php

Need URL as: http://www.mydomain.com/my_folder/configuration.php

Physical Location: (root dir)/demos/my_folder/configuration.php

Need URL as: http://www.mydomain.com/demos/my_folder/configuration.php

Physical Location: (root dir)/demos/site1/my_folder/configuration.php

Need URL as: http://www.mydomain.com/demos/site1/my_folder/configuration.php

Physical Location: (root dir)/demos/site2/my_folder/configuration.php

Need URL as: http://www.mydomain.com/demos/site2/my_folder/configuration.php

Simple so far? Here’s what really needed and makes it complicated (IMO). Consider this:

Config file located at: http://www.mydomain.com/demos/site2/my_folder/configuration.php

Have nested folders: http://www.mydomain.com/demos/site2/1/2/3/index.php

When I access the index.php file in the “3” sub-folder by following the URL above, I need the path to configuration file as http://www.mydomain.com/demos/site2/my_folder/configuration.php and not as http://www.mydomain.com/demos/site2/1/2/3/my_folder/configuration.php

How can I achieve the above?

  • 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-09T15:29:02+00:00Added an answer on June 9, 2026 at 3:29 pm

    If you can rely on the value of $_SERVER[ 'DOCUMENT_ROOT' ], then inside configuration.php:

    $path = substr( __FILE__, strlen( $_SERVER[ 'DOCUMENT_ROOT' ] ) );
    
    $url = "www.mydomain.com{$path}";
    

    If it fits your use case, you can make it more dynamic using $_SERVER[ 'HTTP_HOST' ];

    DOCUMENT_ROOT

    I’ve used DOCUMENT_ROOT liberally in my development, as it’s often the only dynamic variable available for constructing certain self-referential paths. There’s a looong running Apache bug ticket (#26052) about how DOCUMENT_ROOT is poorly handled, particularly that Apache wouldn’t allow you to set the value with RewriteRule and didn’t set it to a sensible value when using mod_vhost_alias. The discussion goes on over a period of 7-8 years as people presumably from the Apache project resist changing the behavior, until they finally came around and made a change this year in 2.4.1. (I looked into this previously, but I forget now what the exact changes were, and how satisfying they are.)

    If you look at the comments on the ticket you’ll see people resisting changes to the behavior with comments like:

    Don’t trust the DOCUMENT_ROOT variable.

    DOCUMENT_ROOT is not, never was, and never will be a reliable way of finding the filesystem path to web content.

    So I suggest reading the comments on that ticket to see what people are saying the caveats of using it are. I’ve used it with a lot of success and don’t know of a better way to achieve the same things in the same situations that DOCUMENT_ROOT is available and provides the necessary data.

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

Sidebar

Related Questions

I have a configuration file to which I want to add a string, that
I have this msbuild target in my csproj file: <Target Name=AfterBuild Condition= '$(Configuration)' ==
I have a configuration file that I consider to be my base configuration. I'd
My application have a configuration xml-file. That file contains more than 50 program settings.
I have a configuration file that i would like to update with classic asp.
I have a configuration file in xml, with increasing specificity. That is, the closest
I have a script which can overwrite values in a configuration file using options,
Using a configuration file I want to enable myself to turn on and off
I have a configuration file that has variables and value separate by spaces. I
My Problem: I have an R script myscript.R that uses a configuration file, e.g.

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.