简体   繁体   中英

.php url to .html 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?

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)

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

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

User-Agent: *
Disallow: *.php

All proper spiders will obey this instruction

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM