HTML: Relative Link without Parameters - html

I have a page name index.php. It is in the folder name test. So if I call localhost/test I can see the page.
I have links in the page that pass parameters:
Link1
Link2
So the URL is localhost/test/?id=1
After that I want to link to the root page (index.php) but I don't want to use href="index.php". I want a link for root page without parameters. So when the user click the link, he/she can go to localhost/test again.
Is there any standard or something?

Try simply using a question mark:
Link1
Link without params

I allways solved this with PHP. In PHP I would have a string variable named '$APP_ROOT' and assign the path to index.php to it. Then you can use this variable to print/echo it in the HTML.
Example (not sure if syntaxt is ok):
<?php
$APP_ROOT = 'localhost/test';
?>
Link1
Link2
With a template engine this could be cleaner. The $APP_ROOT variable needs to be changed when you deploy it to the server.
BUT maybe even more easy is the HTML base tag. I dont know for sure if the base tag is good, I have never used it. Large amount of information is here: Is it recommended to use the <base> html tag?

The "../test" solved my problem.

Related

How to change directory but keep same page url as simple HTML?

Inside a very simple HTML-only website, how to make this happen :
On a page Mysite.com/ABC/mypage.html
Action ; visitor clic on a link, goes to
Mysite.com/XYZ/mypage.html
So with an easy text link like , change the actual pages's previous directory only ?
Could be good easy solution for easy language switch
Is this what you are looking for?
Text
This is because URLs which start with a forward-slash (/) are called 'absolute paths', and refer to the root, i.e. relative to mysite.com
Alternatively, if you want to affect the next directory up only, you can use the following:
Text
This is because .. refers to the parent directory. So if you had a page at example.com/folder1/ABC/mypage.html and you wanted that page to link to example.com/newpages/XYZ/mypage.html, you could do:
Text
There are lots of examples and tutorials online, e.g. https://www.w3.org/TR/WD-html40-970917/htmlweb.html
You can do this:
<a href="../XYZ/mypage.html">
You can change your file name to index.html, or anything else that you set for the default page names in your web browser and you could simply do:
<a href="../XYZ/">
For HTML-only, I believe Kamyar Infinity's comments regarding rewrite rules are your best bet. However, if you're considering using PHP, this might do the trick. It will print the current file name to the after of the desired directory:
text
Alternatively we can use javascript to manipulate the href for this link (without using PHP at all):
text
<script>
//Get current Pagename
var currentPage = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);
//Change href for link
document.querySelector('a[href="/xyz/"]').setAttribute('href', '/xyz/'+ currentPage);
</script>

Link directly to public HTML folder in href inside a Laravel/Blade template

I am using Laravel 5. In a specific Blade template, I have a link that looks like this:
{{ $category->category }}
Normally on my localhost WAMP server, I can access my main page that has this link, like this:
http://localhost:8080/myApp/laravel/public/
When you click the <a> link above, I want the link to simply go to:
http://localhost:8080/myApp/laravel/public/categories/1
Instead, it goes here:
http://localhost:8080/categories/1
If I don't include the leading "/" on categories/1. then it simply keeps adding categories/1 to the url everytime I click it. The first time it works, but the second time (and on) it of course says page not found.
What is the appropriate way to handle routing links in Laravel using the Blade templates?
Try this
{{ $category->category }}

Using HTML href="" on section of URL string

I have a URL www.foo.com/bar/hello/world Can I use href= in such as way:
LinkText
In other words, because of the versioning repository I use for work, only the sublink /hello/world of the final URL will the same when I push the site live.
For reference, see the docs
However, in href, you can either use an absolute URL, such as https://www.foo.com/bar.html or, relative, something like /bar.html, where / refers to the webserver root (but not webserver's system root), or, you can use bar.html which points to a file in the same directory level.
Basically you want to have a /hello/world link, it will point to www.foo.com/hello/world.
If you want it www.foo.com/hello/world to point at www.foo.com/bar/hello/world, you can either rewrite the URL on the server, or, redirect the users to www.foo.com/bar/hello/world
For URL rewriting, see your appropriate webserver docs
Only if the source code is located in 'http://www.foo.com/bar' and then it needs to be going to a valid file extension to execute an action:
LinksText

use a class instead of id in a link

Is it possible to make a link that would normally go to an id:
<a href="http://example.com/page#someid">
instead go to a class:
<a href="http://example.com/page.someclass">
Would the page scroll wildly up and down, trying to reach all the elements with that class, or would it just do nothing?
It would do nothing, except look for a file called "page.someclass" at the server and most probably yield a 404. Please refer to the URL spec because you're wildly confusing CSS selectors with the 'hash' part of the URL.
Why don't just try it?
JS FIDDLE DEMO
If you are using a class als anchor link, your browser tries to open it as url, like in the example named above index.content. Because he is not able to find it, you will receive an 404 not found or 403 forbidden error.

Django how to specify a base url

So there should be a very basic way to do this, but unfortunately I don't seem to be able to find it.
How can one set an Href link to point to the 'base website url' + the 'link', rather than adding the link to the current page.
I.e. if I'm at www.example.com/content1/
I want the search function to go to www.example.com/search/
and not www.example.com/content1/search
I could just specify "www.example.com/search/" but then if it page is deployed locally I end up with a bunch of links to non-existent pages or vice versa. How can I specify the The Base hosting URL using DJango (whichever the server is running, whether the hostname, the current server ip, localhost etc.).
The best way to do this is the name your urls and then use the url template tag. Example below:
First, name your views. Use something like:
urlpatterns = [
...
url(r'^search/$', views.search_view, name="search"),
...
]
In this example, you've got your url for your example.com/search/ view. It is named 'search', which can be used url template tags and using the reverse() function.
Next, in your template, use the url tag with your url name:
Search
You shouldn't need to add 'base website url' to your href, it is implied. Make sure href is prefixed with '/' to set and absolute path and no '/' for relative.
home
is the same as
home
and will work no matter which sub directory you are in
If you are on the homepage and you use the link:
sample
it will effectively equal:
sample
but that same link used on the page http://www.mywebsite.com/sample will equate to:
sample
using:
sample
Will always equate to the following no matter where on the site it is used:
sample
If you are using django consider using the url template tag as Alex suggested:
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#url
Make the link point to /search.
Any link that starts with / is relative to the domain root (say, http://example.com/) whereas any other relative link is relative to the current URL.