What characters are safe for the hash fragment of the URL? - web

e.g. in this url
https://developer.mozilla.org/en-US/docs/Web/API/URL/href#Examples
Examples is the hash part of the URL. I would like to put a secret there because I know servers don't see this component. What characters are safe to put here?

Related

.htaccess how to make my URL shorter?

My current URL:
http://localhost/vavis/public_html/index.html#/users
I wan't to be like this:
http://localhost/users
Looks like you'll need to rely on javascript or something on the client side to handle this. The "/users" part of the url is part of a fragment (after the "#") which isn't even sent to the server, so there's no way anything in the htaccess would know you were trying to access /users.
There's some more information about URL fragments here: https://www.oho.com/blog/explained-60-seconds-hash-symbols-urls-and-seo
So depending on how it got there and why you need it, it may not be as simple as simply removing it or encoding it into something else.

is possible to add more than one '?' in a url?

i need to rewrite url
my Actual URL
http://www.domain.com/page.php?catName/ArticleName....?/&ca=7&prod=44&artId=446
i need to rewrite like this
http://www.domain.com/catID-catName/proID-prodName/artID-ArticleName....?/page.html
Yes it is possible. By the way, your modified URL only has one '?'.
From the [RFC][1] specifying the syntax of URIs and URLs, the query is the part of the URL that follows the http://www.example.com/path or http://www.example.com (the path is optional) component. Note that the "?" character must be the first character of the query section of the URL.
The crucial sentence in the section 3.4 of the RFC is
The characters slash ("/") and question mark ("?") may represent data within the query component.
Here is the pertinent section of the RFC governing URI syntax.
3.4 Query
The query component contains non-hierarchical data that, along with
data in the path component (Section 3.3), serves to identify a
resource within the scope of the URI's scheme and naming authority
(if any). The query component is indicated by the first question
mark ("?") character and terminated by a number sign ("#") character
or by the end of the URI.
query = *( pchar / "/" / "?" )
The characters slash ("/") and question mark ("?") may represent data
within the query component. Beware that some older, erroneous
implementations may not handle such data correctly when it is used as
the base URI for relative references (Section 5.1), apparently
because they fail to distinguish query data from path data when
looking for hierarchical separators. However, as query components
are often used to carry identifying information in the form of
"key=value" pairs and one frequently used value is a reference to
another URI, it is sometimes better for usability to avoid percent-
encoding those characters.
[1]: http://tools.ietf.org/html/rfc3986#section-3

htaccess: Add random string to URL

I'm having a URL like this:
http://www.foobar.com/
If a user enters it, I want the URL to be expanded by a random string like
http://www.foobar.com/f896c0fb0924db5dfeae58d430c2d6ca
(In the example a MD5 is added, but it anything else would be fine too.)
Is it possible to do this via .htaccess and some clever Rewrite-rules?
It is possible to do it with mod_rewrite, but the programmatic mode (prg) needs to be defined in the server config (you can only use them then from .htaccess). You could come close with a long chain of predefined strings (meh) or use other pseudo-random sources. One option is to combine various TIME server variables like TIME_SEC. With repeats and without separators, it would not be easy to notice the pattern.

& Ampersand in URL

I am trying to figure out how to use the ampersand symbol in an url.
Having seen it here: http://www.indeed.co.uk/B&Q-jobs I wish to do something similar.
Not exactly sure what the server is going to call when the url is accessed.
Is there a way to grab a request like this with .htaccess and rewrite to a specific file?
Thanks for you help!
Ampersands are commonly used in a query string. Query strings are one or more variables at the end of the URL that the page uses to render content, track information, etc. Query strings typically look something like this:
http://www.website.com/index.php?variable=1&variable=2
Notice how the first special character in the URL after the file extension is a ?. This designates the start of the query string.
In your example, there is no ?, so no query string is started. According to RFC 1738, ampersands are not valid URL characters except for their designated purposes (to link variables in a query string together), so the link you provided is technically invalid.
The way around that invalidity, and what is likely happening, is a rewrite. A rewrite informs the server to show a specific file based on a pattern or match. For example, an .htaccess rewrite rule that may work with your example could be:
RewriteEngine on
RewriteRule ^/?B&Q-(.*)$ /scripts/b-q.php?variable=$1 [NC,L]
This rule would find any URL's starting with http://www.indeed.co.uk/B&Q- and show the content of http://www.indeed.co.uk/scripts/b-q.php?variable=jobs instead.
For more information about Apache rewrite rules, check out their official documentation.
Lastly, I would recommend against using ampersands in URLs, even when doing rewrites, unless they are part of the query string. The purpose of an ampersand in a URL is to string variables together in a query string. Using it out of that purpose is not correct and may cause confusion in the future.
A URI like /B&Q-jobs gets sent to the server encoded like this: /B%26Q-jobs. However, when it gets sent through the rewrite engine, the URI has already been decoded so you want to actually match against the & character:
Rewrite ^/?B&Q-jobs$ /a/specific/file.html [L]
This makes it so when someone requests /B&Q-jobs, they actually get served the content at /a/specific/file.html.

How to get rid of hash in URL when redirecting?

I have a page with two forms on it. Both are submitted to the original url of the page (action=""), the second one adds a hash segment to it (action="#second-form"). When the second form is valid I want to redirect to another page for a second step, but without #second-form in the url.
Is this possible? It seems like no matter where I redirect the user to #second-form is always retained in the url (e.g. http://www.google.com/#second-form).
Maybe if you try to put this on your code it works..
<base href="http://www.theurlyouwant.com/"/>
Point your action to your filename of the page, instead of "".
E.g. (just a bunch of the same examples for different file names)
action="index.html"
action="index.asp"
action="index.php"
action="form.asp"
action="form.php"

Resources