History.pushState 导航 - 元标记怎么样 - 单独的模板?

发布于 2024-12-02 11:37:05 字数 1722 浏览 1 评论 0原文

我一直在构建一个基于 jquery 导航的网站,无需重新加载(使用 PHP 和 AJAX),最近遇到了页面“后退”、“前进”和“重新加载”功能以及 SEO 友好性的问题。

--跳过本节直接回答问题--

我的网站当前(未使用 AJAX但是)加载一个index.php,它有几个“内容”div,其中一个是可见的(class =“active”),而其他的则不显示。当用户单击导航链接时,会在内容 div 之间切换漂亮的动画。

我有 apache 重写来映射诸如

http://mysite.com/about 之类的东西 到 http://mysite.com/index.php?page=about

其中“about”部分将是默认显示的部分(而其他“content”div 则被隐藏)。基于此参数,我为页面添加了正确的元标记。我的站点地图有 mysite.com/about、mysite.com/blog,以便将它们作为漂亮的单独页面进行索引。

然而,我最近决定使其基于 ajax,因为我计划合并更多内容,并且将所有内容加载到一页上是愚蠢的。

注意:我现在也在实施 Smarty 模板。

我决定实现哈希标签,但看到了固有的 SEO 问题,然后我发现了 hashbangs(什么?!),然后发现了带有 history.pushState()History.js 的新 HTML5 内容 并决定使用它。

所以主要问题来了

如果我只有一个页面使用ajax在内容div中加载页面模板,使用history.pushState()修改URL并使用mod_rewrite和一个PHP后端可以在像“mysite.com/about”(mysite.com/index.php?page=about)这样的直接请求的情况下提供默认内容模板(用于基本可用性和搜索引擎优化),我也无法为直接请求设置元内容除非我有两个模板 -内容模板 - 和元模板?还有另一种方法可以解决这个问题吗?

</code> 和 <code><meta name="description"></code> 这样的标签是否足够重要,足以保证有一个专门针对它们的模板?

总之,我希望我的 mod_rewrite URL 能够在 google 上找到特定的 ajax 加载页面内容模板的正确标题和元描述。

编辑

我想要做的事情与他们在hypem.com上所做的事情几乎相同。它们有一个事件侦听器,当列出新内容时,该事件侦听器会更改 </code> 标记。它们还提供正确的 <code><meta name="description"></code> 标记,但前提是它是对其中一个主页(例如博客)的直接请求 - 其他页面(例如 <a href= "http://hypem.com/blog/indie+today/10332" rel="nofollow">http://hypem.com/blog/indie+today/10332</a>,返回主要的元标记博客页面,并且仅在直接请求时

i have been building a jquery navigation based site without reloads ( using PHP and AJAX ) and have recently come across the problem of page "back", "forward", and "reload" features as well as SEO friendliness.

--skip this section to get straight to question--

my site is currently (not using AJAX but ) loading a single index.php which has several "content" divs, one of which is visible (class="active") while the others are not displayed. When the user clicks a navigation link, a nice animation switches between content divs.

I have apache rewrites to map things like

http://mysite.com/about
to
http://mysite.com/index.php?page=about

where the "about" section would be the one thats displayed by default (while the other "content" divs are hidden). based on this parameter, i include the proper meta tags for the pages. my sitemap has mysite.com/about, mysite.com/blog so that they get indexed as nice separate pages.

However, I've recently decided to make this ajax-based since i plan to incorporate a lot more content and its stupid to load all content on one page.

Note: I'm also now implementing Smarty templates.

I decided to implement hash tags, but saw the inherent SEO problems, then i discovered hashbangs (wth?!) and then found the new HTML5 stuff with history.pushState() and History.js and have decided to use it.

so here comes the main question

if i have just one page which loads page templates in a content div with ajax, using history.pushState() to modify URL and using mod_rewrite and a PHP back-end that can serve a default content template in the case of a direct request like "mysite.com/about" (mysite.com/index.php?page=about) (for basic useabilty and SEO), i cannot also set meta content for direct requests unless i have two templates - a content template - and a meta template? is there another way around this?

are tags like <title> and <meta name="description"> important enough to warrant having a template especially for them?

in summary, i want my nice mod_rewrite URLS to pull up on google with the correct title and meta description for a particular ajax-loaded page content template.

EDIT

i'm going for pretty much the same thing they have going on here at hypem.com. they have an event listener which changes the <title> tag when new content is listed. they also serve the correct <meta name="description"> tag, but only if it is a direct request to one of the main pages, like blogs - other pages, like http://hypem.com/blog/indie+today/10332, return the meta tag for the main blog page, and only when directly requested

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白首有我共你 2024-12-09 11:37:05

我首先构建网站以使用所有直接链接且不使用 ajax,然后添加 ajax。但是,如果浏览器正在请求页面,则仅包含添加 ajax/history 功能的代码。如果网络爬虫访问您的网站,请不要包含 ajax/历史记录功能。

I would first build the site to work with all direct links and no ajax, and then add the ajax. However, only include the code that adds the ajax/history functionality if the page is being requested by a browser. If a web crawler hits your site, don't include the ajax/history functionality.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文