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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:01:02+00:00 2026-05-23T06:01:02+00:00

We can modify the document root directory path for PHP using $_SERVER[‘DOCUMENT_ROOT’] = to/some/new/directory;

  • 0

We can modify the document root directory path for PHP using

$_SERVER['DOCUMENT_ROOT'] = "to/some/new/directory";
//Now the "/" which represent the ^(above) path

in .htaccess we have

RewriteBase "/to/some/new/directory"

Now, I need to modify the root directory path to use in javascript. How to do it?

Currently, I am declaring a variable containing static path to the my personalized root directory and using it as

var root = "../to/new/path";
document.location = root+"/somepage.php";

Scenario

I think i should tell a little bit about the scenario, for you guys to catch my idea

Default Web Root Directory

http_docs/

inside it contain a main folder

http_docs/application <-- contains the actual application
http_docs/js <-- contains the script
http_docs/index.html

Now, the application also contains ajax feature for updating, editing, loading new content, or other resources, which if accessed at “/” will represent at /some/path/i/called not /application/some/path/i/called,

To come around this problem
I can define a static variable like

var root = "application/";

and use it somewhere like

$.post(....., function(data) { $(body).append("<img src='"+root+"resources/img1.jpg"); });

But for a single use, defining the path as static, might not be a big deal, but, when the application grows, and certain modification would cause me to change all the paths i give in the js part. I thought, it would be sensible, just like, I do it in PHP, using <img src="/resources/img1.jpg" />

I tried my best to explain this question, if still is not understandable, please community, lets help them understand. I welcome you to edit my question.

  • 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-23T06:01:02+00:00Added an answer on May 23, 2026 at 6:01 am

    EDITED: Trying to answer the updated question
    Assuming the JavaScript is called included from the index.html file, if you insert a img tag and use relative urls, they will be relative to the path of the index file. So <img src='application/resources/img1.jpg'> would work just fine. If the script should work for several sublevels (e.g. if the page “application/etc/etc2/somePage.html” needs images from “application/resources/”)it may be easier to use absolute urls, and you could include a javascript block on every page generated by php that holds the absolute url to the “root” of the application, like:

    <!-- included by php in all html pages, e.g. in defautlHeadter.php -->
    <script type="text/javascript">
       var rootUrl = "<?= getTheRootUrl() ?>";
    </script>
    

    Where getTheRootUrl() is a method or server variable that gives the root url you need. If the url is translated/remapped (by apache etc. outside of what is visible to php) you may need to hardcode the root url in the php method but at least it will be only one file to change if you ever change the root directory.

    Then you can use the root url to specify absolute paths anywhere in the application/website using rootUrl + "/some/relative/path" in anywhere in the application.

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

Sidebar

Related Questions

How can I modify the PDF document properties programmatically using .NET code? I have
I use the following scheme to include PHP files: require($_SERVER['DOCUMENT_ROOT'] . Path/To/My/Website/Path/To/My/File.php); I would
I want to know I can dynamically modify an existing Crystal Report (using C#
I'm currently trying to modify some HttpWebRequest functions, but I can't do it through
How can I modify a SharePoint site so that versioning is turned on by
How can I modify the NSDatePickerElementFlags for the NSDatePicker in row templates for NSDate
How can you modify the URL for the current page that gets passed to
I have a application deployed through clickonce, but How can I modify the config
How can i clean and modify data from a form in django. I would
I have an @XML document created from a single select statement. <root> <node> <node1>

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.