apache - 规范 URL 和 URL 重写

标签 apache .htaccess url url-rewriting canonical-link

最近我在阅读有关 HTTP 的内容,并遇到了 URL 重写和 URL 规范化。

我读到,当能够从多个 URL 加载同一网页时,会发生 URL 规范化错误,例如:

http://www.example.com

http://www.example.com/

http://example.com

http://example.com/

http://www.example.com/index.php

首先,谁决定输入http://example.com会自动重定向到 http://www.example.com?Is这是我的托管公司服务器中的设置吗?

其次,链接 rel="canonical"是否解决了问题?例如,将以下代码插入页面的头部 http://www.example.com/index.php

<link rel="canonical" href="http://www.example.com" />

如果这解决了问题,我如何检查它是否正常工作?我会看到 URL 从 http://www.example.com/index.php 发生变化吗?至http://www.example.com ?因为我这样做了,但没有看到任何变化。

通过 .htaccess 文件进行 301 重定向比 rel="canonical"解决方案更好吗?

如果我重写(通过.htaccess)http://www.example.com/index.php进入http://www.example.com ,这会是一个解决方案(关于重复的内容)吗?因为对我来说,重写看起来更像是视觉上的变化,而不是其他任何东西。

提前致谢。

最佳答案

First of all, who determines that typing http://example.com will automatically redirect to http://www.example.com?Is it a setting in my hosting company's server?

托管公司的服务器,或者您可以创建 301 重定向以将所有内容定向到规范 URL。

Secondly, does the link rel="canonical" solves the problem? For example inserting the code below inside the head part of the page http://www.example.com/index.php

它会告诉搜索引擎的索引机器人之类的 URL 是相同的,它不会执行任何将您重定向到实际规范 URL 的操作。浏览器甚至可以选择根据具有不同规范 URL 的页面进行缓存。

选择其中之一或两者,取决于您想做什么。您是否希望人们能够访问所有不同的 URL(使用规范链接),还是希望强制所有请求在浏览器的地址栏中看起来相同(使用 301 重定向)。通过 301 重定向,索引机器人还将知道一个 URL 永久重定向到另一个 URL,并且与旧 URL 相关的任何元数据都应该(在某种程度上)应用于新 URL。

关于apache - 规范 URL 和 URL 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25246089/

相关文章:

apache - httpd 2.4 (mod_ssl) 中的每个目录 CA

php - Apache http/https 非 www 到 ww url 重定向

javascript - 清理 url onClick 问题

web-services - GWT 查询服务

ios prefs url路径方案到邮件

java - 如何使用带有 LDAP 身份验证的 Apache Shiro 添加角色授权

php - 在本地主机上模拟慢速连接

sqlite - 如何指定相对 JDBC SQLite url(路径?)

python - PAM认证问题

php - .htaccess RewriteCond,其中 URI 不包含域