Forum Moderators: phranque

Message Too Old, No Replies

Redirect all pages from .htm to .php

Is this the right code?

         

Monkscuba

3:53 am on Mar 7, 2007 (gmt 0)

10+ Year Member



HI,

I just started a new job, in fact, a place I used to work a couple of years ago. In the meantime, people have been playing with the web sites and now all pages are .php rather than .htm since they all have database feeds.

In the .htaccess file there is a line to redirect old links:

RedirectMatch 301 ^(.*)\.htm$ $1.php

It seems to work just fine. However, I do not really want to redirect the home page. With this command, it seems that any link to www.mysite.com is being redirected to www.mysite.com/index.php. I prefer not to have this, and have the index page just displaying as www.mysite.com/ -

is there a way to alter the redirect command to redirect only subpages, but leave the home page alone, unless the link is to index.htm, in which case redirect to index.php..?

Am I making sense? Thanks for any advise and have a nice day

Jamie

grandpa

4:12 am on Mar 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



With this command, it seems that any link to www.mysite.com is being redirected to www.mysite.com/index.php.

The redirect is only affecting any request for a page that ends in htm. This part ( (.*)\.htm ) is taking the page name and storing the value to be reused. The htm part is not saved for later. This part ( $1.php ) is saying, give me the stored value, and stick a php on the end of it. The variable (.*) has been assigned to $1.

is there a way to alter the redirect command to redirect only subpages, but leave the home page alone, unless the link is to index.htm, in which case redirect to index.php..?

I believe that the code is already doing just that.

Monkscuba

10:18 am on Mar 18, 2007 (gmt 0)

10+ Year Member



Thanks for the reply. I have had time to play with it a bit.

We need the redirect since we changed all our pages to .php, but I do not want the home page "http://www.widgets.com/" to redirect to "http://www.widgets.com/index.php".

I would like all links to the home page to be directed to "http://www.widgets.com/", including internal links - just I have read that having some links to / and some to "index.php" can lead to loss of rankings in SE's since they may be treated as 2 different pages.... I realise there is some debate about it.

So can I alter this line

RedirectMatch 301 ^(.*)\.htm$ $1.php

or add something that stops the home page redirecting..?

Thanks to you, Web Gods.

littlebytes

7:26 pm on Mar 19, 2007 (gmt 0)

10+ Year Member



I'm wondering how to convert my site from .php pages to .htm pages without removing the database feature. Is this possible? I heard SE find/index .htm pages easier. Is this true?

bill

12:49 am on Mar 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you had just set up your server to parse HTML files as PHP [google.com] then you wouldn't have to go through this renaming in the first place. This is also another reason to look into cruft-free URLs [google.com] for your site. Technologies will change. If you rely on file extensions like this your future workload will increase when something new comes down the pipeline.