How to work with absolute URL?

Asked

Viewed 173 times

1

I am developed a system and to perform the tests I’m using the xampp. IE, everything is accessible through the address:

localhost/meusite/...

To call all links on my site, as well as include files, I’m using absolute url, for example:

"localhost/name1.php"
"localhost/hostname/folder/pagename.php"

Everything is working perfectly, but currently there are more than 50 files that I developed, the problem is that when I host, I have to rewrite each link/include/call of each file? Is there any way I can do absolute url writing without this folded job?

I thought about using relative url, but when I do this because of . htacess the urls end up giving error.

1 answer

0


Are you programming in PHP right? Then you can create a file called config.php and set the BASE URL on it. Example:

<?php
 define('BASE_URL','http:/localhost/nomedosite/'); 

And in the other files you just make the configuration call like this:

<?php
require_once('config.php');
?>
<html ...>
<body>
<a href="<?php  echo BASE_URL; ?>pasta/paginapasta.php">meu link para outro arquivo</a>

Ai when you need to change the base just change the settings file config.php.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.