Forum Moderators: phranque

Message Too Old, No Replies

Redirect all google's cached pages from asp to php on very large site

incoming url redirect by changing extension

         

jimmbo

5:54 pm on Feb 14, 2011 (gmt 0)

10+ Year Member



I am recoding an entire website from ASP to PHP on a new server because the old server running Chillisoft into MySQL has been hacked and it cannot be recovered so it has been turned off permanently. The new server has the same IP address as the old one. Google has a cache of about 50,000 pages from this website with the extension .asp. The cached pages have the form: www.mywebsite.com/somedirectory/somefile.asp?id=123456.

What is the best way to have the new server respond to a cached Google URL that points at an .asp page and change it so the new server delivers the corresponding dynamic php page - eg: www.mywebsite.co./somedirectory/somefile.php?id=123456.

The new site will use exactly the same directory structures as the old site and all its internal links will point correctly to php pages. There will be no .asp pages anywhere.

Ideally I want Gooogle to eventually re-index the entire new php site as it has been on page 1 for the last 10 years!

Any help/comments will be gratefully received.

jimmbo

2:19 pm on Feb 15, 2011 (gmt 0)

10+ Year Member



As a newbie to Apache I wondered if the following would do the trick:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/([^./]+)\.asp$ /$1.php [R=301,L]

I understand mod_rewrite keeps the query string intact. If I put this in the .htaccess file at the site root, would it work? (The server has about 40 other sites on it so the solution must be site based). Before I screw things up I just need some reassurance!

g1smd

6:29 pm on Feb 15, 2011 (gmt 0)

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



Just because the files on the server have a different extension, doesn't mean that the URLs that people use out on the web to access your website have to change.

You can name your files as .php and set up an internal rewrite to convert URL requests for .asp URLs to fetch content from .php files.


You can name your files as .asp and tell Apache to parse them for PHP instructions.

There are multiple ways to tackle this, a simple redirect to new URL may not be the best one. That's because there will be ranking and traffic drops lasting many months if you choose to change the URLs that are used to access the site.

jimmbo

11:23 am on Feb 16, 2011 (gmt 0)

10+ Year Member



OK: So if I name the files on the new server as .php (and they will all be re-coded as such) I can set up the internal rewrite to convert requests for .asp files to fetch the equivalent .php file - with the query string intact of course.

Will the following .htaccess file in the website root do this?

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/([^./]+)\.asp$ /$1.php [R=301,L]

This will preserve the URL's cached on Google but I also want to ensure Google scans the site and adds the new .php files to its cache. This way I can gradually replace all the outdated .asp files without killing the site ranking. What additional line in the .htaccess file would you add - or is the above sufficient?

g1smd

8:20 pm on Feb 16, 2011 (gmt 0)

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



Take out the R=301 flag. The R flag makes it a redirect, not a rewrite.

Remove the leading slash from the RegEx pattern if this code lives in a .htaccess file.

jdMorgan

1:27 am on Feb 18, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the .asp URLs used to include any directory paths, then

RewriteRule ^/(([^/]+/)*[^.]+)\.asp$ /$1.php [R=301,L]

would be a better generic/more-flexible pattern. It allows for rewriting /dir/foo.asp to /dir/foo.php and it also allows URLs with periods in directory names to be rewritten, as in /dotted.dir/bar.asp to /dotted.dir/bar.php

As g1smd points out, the leading slash on the pattern should be removed if this code goes into .htaccess or into <Directory> section in a server config file.

Jim

jimmbo

10:35 am on Feb 18, 2011 (gmt 0)

10+ Year Member



Thanks you both for the replies. I tried using

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([^./]+)\.asp$ /$1.php [,L] with and without the R=301 flag but this led to a server 500 error. The .htaccess file was placed in the web folder containing the website files. On my linux server all the websites are held as follows:

/home/.sites/xx/sitexx/web

I placed the .htaccess file inside the web folder so...

web
folder1
folder2
index.php
.htaccess

I am running PHP 5.1.6

The error occurred when I used a browser to call up www.mysite/myfolder/asp?id=123456

I need a solution to redirect the browser call when received at the server to a real php file using exactly the same configuration name within a folder called "phpfiles".

Any further ideas will be much appreciated.

jdMorgan

5:36 pm on Feb 18, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First idea: Read my post above about subdirectory support. The code you tested won't support subdirectories.

Second idea: What did your server error log have to say about this error? You can't debug problems effectively if you don't read the error log...

Jim

jimmbo

9:21 am on Feb 19, 2011 (gmt 0)

10+ Year Member



Jim, thanks for the response - I had incorrectly copied your Rewrite rule - (rushing!) so will try the correct version on Monday when I have server access again.

Jim

g1smd

6:49 pm on Feb 19, 2011 (gmt 0)

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



Be sure you fully understand the difference between an external redirect and an internal rewrite.

Although the code for both is similar, they are completely different things.

An incoming URL request arrives at the server. For a redirect, the browser is told to go make a new request for a new URL. For a rewrite, the incoming request will be connected to a file inside the server, but that file will be different to the one suggested by the path of the URL mentioned in the incoming request.

The redirect code will mention the domain name in the target and will include the R flag (and the L flag). The rewrite code will not mention a domain name and will have only the L flag.

jimmbo

11:53 am on Feb 22, 2011 (gmt 0)

10+ Year Member



g1smd, thanks for the reminder about rewrite and redirect. I have tried to use the Rewrite as follows with .htaccess placed loose at the website root:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(([^/]+/)*[^.]+)\.asp$ /$1.php [L]

I get an error: ...[client ip adress]/home/.sites/xx/yy/web/.htaccess: Options not allowed here

Does this mean the line Options +FollowSymLinks above is causing the problem - and is it required?

jdMorgan

6:14 pm on Mar 4, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It may or may not be required.

Test by commenting it out.

If you then get an error that the "RewriteEngine on" directive is not recognized, then the Options directives was in fact required, and you'll have to ask you host to enable "AllowOverride Options" in your server config file, or to set "FollowSymLinks" in that config file.

Basically, Options FollowSymLinks is required if you want to use mod_rewrite, so it must be enabled either in the server config or in your .htaccess file.

Jim