Using root urls and problems with local testing

I use XAMPP to test sites locally, but I'm having problems using root URLs with root privileges http: // localhost / rather than http: // localhost / test-site / , where the site files are stored. Obviously, when I upload the site to a remote server everything works fine, but it makes testing locally annoying when the stylesheet doesn't even load.

Is there any around this problem?

MTIA.

(Mohamed, I'm not sure why you edited my tags - there was no mention of php in my post, so I don’t know why you added php as a tag. In addition, the message refers to html and localhost, so I used the tags " html "and" localhost "as tags and retrieve tags. If I post messages incorrectly, I would appreciate an explanation of why and how I can ensure that I post correctly in the future ..)

0
source share
2 answers

You can use constants in the settings file or in index.php:

define('LOCAL_URL', 'http://localhost/test-site/'); define('DISTANT_URL', 'http://domain.tld/'); define('DEV_VERSION', true); 

And then:

 if(DEV_VERSION) define('URL', LOCAL_URL); else define('URL', DISTANT_URL); 

This way you can just use the URL constant in your code, for example:

 <link rel="stylesheet" type="text/css" href="<?php echo URL; ?>style/site.css" /> 

The advantage is that it works in all cases.

And just add debug controls:

 if(DEV_VERSION) error_reporting(E_ALL ^ E_DEPRECATED ^ E_USER_DEPRECATED); else error_reporting(0); 
0
source

The most convenient solution is to create a dedicated domain for each test site.
I'm sure XAMPP even has some tool for this task, making these few automatic changes to files automatically

0
source

Source: https://habr.com/ru/post/900665/


All Articles