Suppose my page URL is: http://example.com/path/to/dir/index.html
And I proxy this page via: http://proxyserver.com/path/to/dir/index.html
.
Similarly I want all relative URLs in page to be resolved by proxyserver.com
instead of example.com
. What should be the proper <base>
href value?
I want relative URLs on page like
newfile.html
to resolve tohttp://proxyserver.com/path/to/dir/newfile.html
/newfile.html
to resolve tohttp://proxyserver.com/newfile.html
#hash
to resolve tohttp://proxyserver.com/path/to/dir/file.html#hash
Setting <base href="" />
in page does the job correctly but does it have some implication? Does it have different interpretation across browsers? What does empty href
value actually mean? Will it work for all frameworks like angular?
I have heard that <base>
tag is mandatory for angular apps to initialize and hence removing <base>
tag might not work.
NOTE: The website may already contain some <base>
tag which I would always like to override.
I also tried <base href="/" />
but it will resolve relative URLs
newfile.html
tohttp://proxyserver.com/newfile.html
and#hash
tohttp://proxyserver.com/#hash
which is wrong.
Any help is highly appreciated.
A base URL, or base location, is the unique root URL with which relative URLs can be converted into absolute URLs for a website. Multiple bases are impossible.
More complex, inconsistent policies can be enforced with redirection rules. This duty belongs to the web server. To list few, NginX, Apache and IIS all have the ability to set redirection rules. There you can do whatever you like with regular expressions.
Since this question is tagged Angular, then, since client-wise a page is accessed only after the web server resolves an http request, you would have to create a blank page redirecting to the correct page for every wrong case. Which is of course worse than letting the web server handle redirections.