Need make redirect from http://sitename.com/cat/index.php to http://sitename.com/cat/index.php#anchor
I tried 2 ways: php redirect and meta refresh
PHP redirect
<?php
$URL = "http://sitename.com/cat/index.php#anchor";
header("Location: $URL");
?>
<html>
....
meta refresh
<html>
<head>
...
<meta http-equiv="refresh" content="0;url=http://sitename.ru/cat/index.php#anchor">
...
</head>
...
</html>
In result to both ways I have cycling page refresh.
How to correctly solve this problem ?
One can use the anchor tag to redirect to a particular section on the same page. You need to add ” id attribute” to the section you want to show and use the same id in href attribute with “#” in the anchor tag.
If the anchor you are linking to is on a different page as the link: In the pop-up box, click the Link to dropdown menu and select URL. Enter the full URL of the page followed by the # hashtag symbol, followed by the name of the anchor. Click Insert.
The server can only redirect the link at page level. It cannot redirect incoming anchor links, because it never sees the anchor part of the URL.
You likely want to put that information elsewhere rather than in the href itself. As you are using jQuery, I'd suggest storing it in an HTML5 data-* attribute (at which point you can put javascript:; into the href to prevent the browser loading a whole new page.
You don't need to redirect the page, just set the window.location.hash
.
window.location.hash="anchor";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With