Reputation: 1946
If I have an index.html
file and it contains multiple pages. When I load the page, I want the URL to contain the hash #first
, aka index.html#first
. Instead, the URL says index.html
.
My work around so far to is to have a fake first page and then link directly to index.html#first
, hopefully never showing the "real" first page, aka index.html#fake
.
Is there a better way of doing this?
<body>
<!--
fake page
-->
<div data-role="page" id="fake">
<div data-role="content">
fake
</div>
</div>
<!--
first
-->
<div data-role="page" id="first">
<div data-role="content">
first
</div>
</div>
<!--
second
-->
<div data-role="page" id="second">
<div data-role="content">
second
</div>
</div>
</body>
Upvotes: 0
Views: 373
Reputation: 14800
Configure your web server so requests for "index.html" and requests for '/' (path with no file!) return a 301 Moved Permanently
response to redirect to 'index.html#first'
That said, I can't imagine why you want to force the hash onto the url; maybe a library that's not robust enough? Correctly coded, http://example.com/
, http://example.com/index.html
, and http://example.com/index.html#first
can and should (IMHO) all behave the same.
Upvotes: 0
Reputation: 70414
Why don't you check in JS if the hash code is present on index.html page and if it's not then you can redirect the browser to index.html#first
$(function () {
if (window.location.hash.length == 0) {
window.location = window.location.href + '#first';
}
});
Upvotes: 1