隐藏“重复内容”使用 mod_rewrite 删除 .php 文件扩展名后来自 Google

发布于 2024-12-24 04:02:22 字数 489 浏览 0 评论 0原文

抱歉,这个标题有点神秘!我会尝试解释一下。我的 .htacess 中有以下内容:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

因此用户可以输入 domain.com/foo/bar 并提供 domain.com/foo/bar.php 。当然,输入 domain.com/foo/bar.php 也会加载相同的页面。

因此,在 Google 网站管理员工具(在 HTML 建议下)中,Google 认为我已经复制了所有元描述和标题标签,因为它将 bar 和 bar.php 视为两个不同的文件。我担心谷歌会惩罚这种“重复内容”。我应该怎么办?我确信我不是第一个遇到这个问题的人,但我正在努力寻找相关的问题/答案。

感谢您的帮助

Sorry for the somewhat cryptic title! I'll try to explain. I have the following in my .htacess:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

So users can type domain.com/foo/bar and domain.com/foo/bar.php is served. Of course, typing domain.com/foo/bar.php also loads the same page.

So, in Google Webmaster Tools (under HTML Suggestions), Google thinks that i have duplicated all my meta descriptions and title tags as it sees bar and bar.php as two different files. I am worried Google will penalise this "duplicate content". What should i do? I am sure im not the first one to have this issue, but i am struggling to find related questions/answers.

Thanks for any help

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

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

发布评论

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

评论(2

音盲 2024-12-31 04:02:22

使用[R](重定向标志)

RewriteRule ^(.*)$ $1.php [R,L]

这会强制进行外部重定向,因此尝试访问domain.com/foo/bar.php的用户将被重定向(通过HTTP 302 Found)到domain.com/foo/bar。您还需要使用 [L](最后一条规则),以便立即发生重定向。

Use [R] (the redirect flag).

RewriteRule ^(.*)$ $1.php [R,L]

This forces an external redirect, so users who attempt to access domain.com/foo/bar.php will be redirected (through HTTP 302 Found) to domain.com/foo/bar. You'll also want to use [L] (last rule), so that the redirect happens immediately.

静赏你的温柔 2024-12-31 04:02:22

我使用的答案(根据我原来的评论)从这里解决了我的问题

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php?\ 
HTTP RewriteRule (.+)\.php?$ http://www.domain.com/$1 [R=301,L] 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(([^/]*/)*[^/.]+)$ /$1.php [L]

The answer i used (as per my original comment) from here which solved my problem

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php?\ 
HTTP RewriteRule (.+)\.php?$ http://www.domain.com/$1 [R=301,L] 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(([^/]*/)*[^/.]+)$ /$1.php [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文