.php url to .html url

2019-02-25 10:42发布

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?

3条回答
Lonely孤独者°
2楼-- · 2019-02-25 10:57

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

User-Agent: *
Disallow: *.php

All proper spiders will obey this instruction

查看更多
女痞
3楼-- · 2019-02-25 11:09

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

查看更多
放我归山
4楼-- · 2019-02-25 11:21

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)

查看更多
登录 后发表回答