.php 网址到 .html 网址
我有一个用 .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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更新不合作的评论(谢谢大家)
添加另一个重写规则,在其他规则之前将所有 *.php 重定向到 *.html 文件。
类似的东西:
将所有 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:
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)
您不能将 .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.
最简单的方法是简单地拒绝 robots.txt 中的“.php”。
所有合适的蜘蛛都会遵守这个指令
Easiest way is to simply deny ".php" in your robots.txt.
All proper spiders will obey this instruction