Forum Moderators: phranque

Message Too Old, No Replies

301 Redirect to forward with ".php" extension

         

tec4

7:40 pm on Jun 16, 2011 (gmt 0)

10+ Year Member



I'm trying to preserve a website's SEO after leaving a provider. The old CMS automatically populated the extension ".php" and the new CMS populates it wihtout the ".php". I also try to place the .php in the url when creating a page, but it sanitizes the "." in the string and thus, what I would like to be "/buying.php" comes out to "/buyingphp".

I am now wondering if I can re-direct a page that I've created through the new cms to re-direct to the .php extension to preserve the seo...but am having difficulty doing so.

Ive tried this 301 redirect but didn't seem to work:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^selling$ "http\:\/\/www\.example\.com\/buying\.php" [R=301,L]


Anyone have any ideas or suggestions on how to go about redirecting to the buying.php page?

Had also heard that this would work, but hasn't for me:

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]



...this is how my pages are configured within .htaccess

RewriteRule ^([A-Za-z0-9\-]+)$ /page.php?category=$1 [L]

Any Suggestions?

g1smd

8:11 pm on Jun 16, 2011 (gmt 0)

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



Your first block of code is for an external redirect.

Your second block of code is for an internal rewrite.

You need to decide which thing you want.

In this case you need an external redirect, and it should redirect the old .php URL requests to the new extensionless URL, because those are the URLs that the site now uses:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.php
RewriteRule ^([^.]+)\.php$ http://www.example.com/$1? [R=301,L]