如何在不重新加载页面的情况下更改地址栏上的url [英] how to change url at address bar without reloading the page

查看:177
本文介绍了如何在不重新加载页面的情况下更改地址栏上的url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 http://mysite.com/index.php .

还有一个子菜单

  • home => http://mysite.com/index.php
  • about us => http://mysite.com/about.us.php
  • products => http://mysite.com/products.php

但是我希望 http://mysite.com/index.php 处理每个请求,并且只需使用Ajax请求更改内容.这样,该网站仅加载内容部分,并且速度更快且易于导航.

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.

这里的问题是SEO,因为Google只能看到的URL是 http://mysite.com/index. php ,我想将 http://mysite.com/about-us 关联到关于我们内容, http://mysite.com/product 产品内容等

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.

我知道我可以使用PHP做到这一点,只需读取URL并即时编写Ajax,但是这样做每次都将重新加载整个页面. 有没有一种方法可以在不重新加载整个页面的情况下执行此操作? 我认为我需要在子菜单中有一个常规锚点,例如指向" http://mysite.com/contact-us ",但单击而不是打开此页面,而是处理Ajax请求.

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.

如果可能的话,Google可能会将其视为黑帽,对吧?

And if this is possible, Google is going to see this as black hat probably, right?

问候 亚历克斯

推荐答案

您不能在不更改页面的情况下更改地址栏中的URL,因为为了能够做到这一点,我无法通过

you can't change the URL in the address bar without changing the page because to be able to do that I couldlet you visit me at http://www.imhackingyou.com/sucker but change the addressbar to read http://www.bankofamerica.com/login

这篇关于如何在不重新加载页面的情况下更改地址栏上的url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆