3

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 Answers 3

6

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)

Sign up to request clarification or add additional context in comments.

5 Comments

You forgot the backslash, and to ask to keep the query param in the forwarding (QSA): RewriteRule ^(.*)\.php$ $1.html [R=301,QSA,L]
"guy s "? I'm the only one here! =)
Hi thanks for the help but need one more help/confirmation. i am using following rules. please let me know should i remove any of them or keep as it is.Options +FollowSymLinks RewriteEngine on RewriteRule ^(.*)\.php$ $1.html [R=301,QSA,L] RewriteRule ^(.*)\.html$ $1.php ErrorDocument 404 /404.php RewriteCond %{HTTP_HOST} ^example\.com RewriteRule ^(.*)$ example.com/$1 [R=permanent,L]
as i used ur suggestion my site stopped working. it says redirected to wrong page. i used this RewriteRule ^(.*)\.php$ $1.html [R=301,QSA,L]
"This webpage has a redirect loop" it say so.
0

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

4 Comments

only works if php is setup to parse *.html files (not recommended)
Why isn't this recommended? So as to keep a clear definition on what has php and what doesn't?
If you configured your scripts to allow *.html uploads (which is normally no problem), they get parsed if you open them. The problem is, that you can now arbitary php code without verification or something.
my site is built in php with open cart installed in it. So i cannot rename .php files to .html. if i do that my cart will not work. So i have converted .php to .html for content pages by using mod rewrite. but the issue is my website is showing in both .php and .html in search engines which is very bad as per seo and also its considered as duplicate content by search engines. so please help me guys. criss i tried your suggestion too but its not working. it says "the web page has a redirect loop". so tell me any other way out. thanks in advance.
0

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

User-Agent: *
Disallow: *.php

All proper spiders will obey this instruction

4 Comments

Problem with this is, spiders may already have crawled the site. so what happens the enxt time they crawl the page? either delete the sites or leave it in the index. better would be a 301 redirect (moved permanently).
They would load the robots.txt the next time they visit and act accordingly. I have just used this same approach to get rid of several pages on google. Simple and straight forward.
but how does it help in search results? and for users? will solve duplicate content problem?
It tells bots not to visit any pages ending in ".php" and thus not record them. Previously recorded ".php" pages will drop out of google over time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.