.php 网址到 .html 网址

发布于 2024-12-22 01:15:28 字数 489 浏览 3 评论 0原文

我有一个用 .php 构建的网站,但我们已使用“mod rewrite” 将其转换为 .html.htaccess 中使用的 mod 重写代码是

RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php

现在的问题是我的网站同时出现在 .php.html 中。

例如:www.mydomain.com/index.html 以及 www.mydomain.com/index.php

据我所知,它不利于搜索引擎优化,而且可能会出现搜索引擎重复的内容。

所以我只想在搜索引擎和用户上保留 .html [not .php] url。

怎么办?

I have a website built in .php but we have converted it to .html by using "mod rewrite". the mod rewrite code used in .htaccess is

RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php

Now the problem is my website shows up in both .php and .html.

for example: www.mydomain.com/index.html and also www.mydomain.com/index.php.

as per my knowledge its not good for seo purpose and also it may fall in duplicate content to search engines.

so i want to keep only .html [not .php] url live on search engines and for users.

how to do that?

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

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

发布评论

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

评论(3

我ぃ本無心為│何有愛 2024-12-29 01:15:28

更新不合作的评论(谢谢大家)

添加另一个重写规则,在其他规则之前将所有 *.php 重定向到 *.html 文件。
类似的东西:

RewriteRule ^(.*).php$ $1.html [R=301,QSA,L]

将所有 php 文件重定向(R 标志)到具有永久重定向(301)的 html,并停止处理其他所有内容(L 标志)。它还转发所有查询参数(QSA 标志)

UPDATE incoorperated comments (thanks guys)

add another rewrite rule which redirect all *.php to *.html files before your other rule.
something like that:

RewriteRule ^(.*).php$ $1.html [R=301,QSA,L]

that redirects (R flag) all php files to html with a permanent redirect (301) and stops processing everything else (L flag). also it forwards all query parameters (QSA flag)

扮仙女 2024-12-29 01:15:28

您不能将 .php 文件重命名为 .html 并删除 RewriteEngine 规则吗? PHP 仍应按预期运行。

Can you not just rename the .php files to .html and delete the RewriteEngine rules? The PHP should still all run as expected.

谜泪 2024-12-29 01:15:28

最简单的方法是简单地拒绝 robots.txt 中的“.php”。

User-Agent: *
Disallow: *.php

所有合适的蜘蛛都会遵守这个指令

Easiest way is to simply deny ".php" in your robots.txt.

User-Agent: *
Disallow: *.php

All proper spiders will obey this instruction

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