The base
element is used for relative URLs. If you use a full URL for an a
element, img
element, link
element, etc the base
element will simply be ignored. The base
element is extremely useful for when you want to test local versus live (as you should always test locally first). You can not choose for the base element to only apply to certain situations unless you want to get in to extremely convoluted JavaScript which I don't recommend.
Base Element
<base href="https://www.example.com/" />
Relative URLs
<link href="themes/default/style.css" media="screen" rel="stylesheet" type="text/css" />
<img alt="Example" src="images/test.png" />
<a href="loans/">Loans</a>
<a href="loans/sum/">Loan Sum</a>
Use index.php
in the folder loans/sum/[index.php]
to create clean URLs if you're not using something such as Apache rewrites.
Effective URLs
https://www.example.com/themes/default/style.css
https://www.example.com/images/test.png
https://www.example.com/loans/
https://www.example.com/loans/sums/
Most people start out with convoluting their setups. You should only have the domain name's root most directory (as demonstrated above) and make all your URLs relative.
For the base
element itself you should use PHP to determine whether the site is local or live and then echo the appropriate path; that way you don't any convoluted setup like needing two separate copies of the site.
You will want to split your base
element's PHP code in to two parts; for the live site the $url2
should only be /
and then since you'll naturally have other projects archived and/or in development then for localhost
you'll change the path accordingly.
Base Element PHP - Part 1
`<?php echo '<base href="'.$url1.$url2.'" />' . "
";?>`
Base Element PHP - Part 2
You'll have to do a little bit of work here but this should open your mind up to other juicy possibilities for down the road to make your life easier plus I don't know all your local directory structures. So explore the $_SERVER
array to start putting together the $url1
string and remember to keep it simple.
<?php echo '<pre>';print_r($_SERVER);echo '</pre>';?>