How can i change url without reloading page in php?
I have http://mysite.com/index.php. Show And a sub menu
But i want http://mysite.com/index.php to process every request, and just change the content using Ajax request. This way, the site only loads the content part, and is much faster and easy to navigate. The problem here is SEO, because the only URL google will see is http://mysite.com/index.php and I would like to associate http://mysite.com/about-us to the About Us content, http://mysite.com/product to the Products content, etc. I know I can do this with PHP just reading the URL and writing the Ajax on the fly, but doing so the whole page is going to be reloaded every time. Is there a way to do this without reloading the whole page? What I think I need is to have a regular anchor in the submenu, for exampel pointing to "http://mysite.com/contact-us" but when clicked, instead of opening this page, process the Ajax request. And if this is possible, Google is going to see this as black hat probably, right? Regards Alex asked Dec 17, 2010 at 22:38
Alex AngelicoAlex Angelico 3,4168 gold badges30 silver badges47 bronze badges 3 This is a routing issue, not an AJAX issue. If you were using another tool (cough ASP.NET MVC cough), you'd just add a route (and I'm hopeful there's a way to do this in PHP) that accepted URLS like
and routed them to, say,
This is typically
accomplished with a rewrite engine when used outside of a good MVC or RESTful URL system. I use ISAPI Rewrite on IIS, but if you're working on the LAMP stack, I think Apache provides a module that provides the same capabilities. (Google WARNING: RANT FOLLOWS And, for what it's worth,
Rules:
answered Dec 17, 2010 at 22:44
3Dave3Dave 27.9k18 gold badges84 silver badges150 bronze badges 1 How does Shopify do it then? Go to their website, click on the Features link and you'll see the URL says: http://www.shopify.com/tour/sell-online Then click on any of the sub links and you'll see that the address in the URl changes without using a hash but there is no page flip. I don't think they are using ajax to change the content because it all appears to be included in hidden divs on the page, but regardless, you can apparently change the URL using client side tricks. answered Nov 16, 2012 at 18:07
Julian DormonJulian Dormon 1,6374 gold badges31 silver badges55 bronze badges I would like to access the portion before the # hash if possible. I only need to change the portion after the domain, so it's not like I'm violating cross-domain policies. window.location.href = "www.mysite.com/page2.php"; // Sadly this reloads Is there a way I can modify the URL of the current page without reloading the page? Jun 20, 2020 in Java-Script by• 37,510 points • 3,817 views 1 answer to this question.Hii @kartik, HTML5 introduced the history.pushState() and history.replaceState() methods, which allow you to add and modify history entries, respectively. window.history.pushState('page2', 'Title', '/page2.php'); Hope this is helpful!! answered Jun 20, 2020 by Niroj• 82,780 points Related Questions In Java-Script
Subscribe to our Newsletter, and get personalized recommendations.Already have an account? Sign in. How do I modify the URL without reloading the page?Method 2: Adding a new state with pushState() Method: The pushState() method is used to add a new history entry with the properties passed as parameters. This will change the current URL to the new state given without reloading the page.
How can I change the current URL in PHP?php if (! $_GET["name"] && $_GET["id"]) { // perform MySQL query to get name based on id header("Location: http://www.something.org/zzz"); die(); // stop execution of this page } // if we got here, $_GET["name"] is set, so do whatever this script is supposed to do. ?> NOTE: The above .
How do I change the URL after Ajax success?You can do this to your success action : window. history. pushState("object or string", "Title", "/new-url");
How do I change the URL on my browser?There are basically two ways to change the URL displayed in the browser* through javascript without reloading the page.. window.history.pushState(“object or string”, “Title”, “/new-url”);. window.history.replaceState(“object or string”, “Title”, “/another-new-url”);. |