Good Day! I've got some trouble on PHP. If I click an href which is this <a href = 'members/loans/loan-application-form.php'>
it goes to the loan-applicaton-form.php, but if i click it again inside the loan-application-form.php (cuz it is located at the navbar that exist in all pages) the href of the anchor concatenates on the existing url and it creates an error telling that address is not existing. I already knew that the problem is it searches the address on the current directory and probably it will return an error because there is no existing address on the directory because it is the origin or the parent. What is the best way to avoid this?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
By specifying relative Urls like so:
You are simply stating you wish to go form the current page to this page, hence why it is being added to the end of the current URL. The best way to avoid this quite simply is to set an absolute URL like so:
Even when not using
http://
it is often still considered relative so be sure to include this.Another way to do the same but slightly quicker would be to add a variable in say your header file for example:
Then when specifying the URLs you can do say:
This just means that should you say change your domain, rather than editing every URL you can simply edit the variable value and be done with it.
You can use an absolute path
Advice : you can read this article
or this stack question
Or you can use
../
to navigate inside your relative pathLets imagine your nav bar is located at /navigation/navbar.html
Then you can have a relative path like
Add a
base
tag to your header. This will prepend all HTML URL's with the given base URL. (Including images, CSS and JS calls)Your URL will then be
http://www.yourdefaulturl.com/members/loans/loan-application-form.php