XAMPP Relative URLs Not Working Correctly

at http://www.exampleSite.com/aPage.php , the following image loads correctly

<img src="/images/sidenav/analysis-2.gif" /> 

but in http: //localhost/exampleSite/aPage.php , it tries to get localhost / images / ... instead of localhost / exampleSite / images / ...

My file structure:

C: \ XAMPP \ HTDOCS \ exampleSite \

I had a problem with several projects, and they had previously resorted to absolute URLs, but now I'm just trying to make some quick updates on the page, and I cannot view it correctly on my local host.

+4
source share
2 answers

If you do not want to spoil the src attributes on your website, you can consider changing the configuration directives.

You can move it by editing the DocumentRoot parameter in C:\xampp\apache\conf\httpd.conf .

Currently, it should be installed as:

 C:/xampp/htdocs 

Change it to:

 C:/xampp/htdocs/exampleSite 

and your relative link as <img src="/images/sidenav/analysis-2.gif" /> should work fine.

Note:

  • Remember to restart the XAMPP server after making the changes.
  • After these changes, the lead / will always be directed to the exampleSite folder. If you decide to change the root later, repeat the process for the root folder of your choice.
+13
source

Remove first / so that it becomes

<img src="images/sidenav/analysis-2.gif" />

+5
source

All Articles