.php url .html url

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

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

Now the problem is that my site is displayed in both .php and .html .

for example: www.mydomain.com/index.html , as well as www.mydomain.com/index.php .

according to my knowledge, this is not good for SEO purposes, and it can also get into duplicate content in search engines.

therefore I want to save only .html [not .php] url in search engines and for users.

how to do it?

+3
source share
3 answers

UPDATE incoorperated comments (thanks guys)

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

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

which redirects (R flag) all php files to html with a constant redirect (301) and stops processing everything else (L flag). it also sends all request parameters (QSA flag)

+6
source

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

0
source

The easiest way is to simply disable ".php" in your robots.txt file.

 User-Agent: * Disallow: *.php 

All correct spiders will follow this instruction.

0
source

All Articles