Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite from ASP to PHP/Drupal

         

Fotiman

5:09 pm on Aug 8, 2011 (gmt 0)

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



Scenerio:
Website was originally developed using ASP. The site has been redesigned and is using PHP/Drual now. I want to redirect old links to their new locations.

Many of these links come from a single dynamic page, as in:
/discussion2.asp?T=102
/discussion2.asp?T=108
/discussion2.asp?T=114

I need to map each of these to their new location. Unfortunately, the new locations look nothing like the original. For example:

/discussion2.asp?T=102
needs to go to:
/content/some-page-about-foo

/discussion2.asp?T=108
needs to go to:
/content/everything-bar

In other words, I think I need to manually map these pages 1-to-1. I don't have much mod rewrite experience, and would appreciates any tips. I think I need to do something like this:

rewriteCond %{REQUEST_URI} ^.*discussion2\.asp$
rewriteCond %{QUERY_STRING} ^T=102$
rewriteRule ^.*$ /content/some-page-about-foo [R=301,L]

rewriteCond %{REQUEST_URI} ^.*discussion2\.asp$
rewriteCond %{QUERY_STRING} ^T=108$
rewriteRule ^.*$ /content/everything-bar [R=301,L]

Does that look correct?

g1smd

5:20 pm on Aug 8, 2011 (gmt 0)

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



There's a much better way.

Rewrite incoming requests to a new PHP script that contains an array of old and new URLs and sends the correct HTTP 301 HEADER response.

There's several prior threads with detailed example code examples.

RewriteCond %{QUERY_STRING} T=
RewriteRule ^discussion2\.asp /special-script.php [L]


The query string is re-appended by the rule and the PHP script then uses the T value to look up the new URL.

Fotiman

7:32 pm on Aug 8, 2011 (gmt 0)

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



Cool. I will have to look into that. Thanks.

Fotiman

6:47 pm on Aug 9, 2011 (gmt 0)

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



Another question... if I have more than just this page to redirect, is this still the best way to go about it? For example, according to Google Webmaster Tools, the site has 333 internal links. Many of them are pointing to discussion2.asp with a query string value, but others have changed as well. For example, "/aboutus.asp" needs to be redirected to "/content/about-us". Should I create rewrite rules for all of the static pages, or just have all .asp URLs redirect to special-script.php and manage them from there?

Also, do you have examples of a PHP script that would produce the correct 301 headers for those links?

g1smd

7:07 pm on Aug 9, 2011 (gmt 0)

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



There's a thread a few months back with outline PHP code in. It was repeated several times over the next few weeks as the same question came up several times in one month.

If the other redirects do not use parameter values, then simply create a redirect for each one in the .htaccess file. Use the special PHP script only for the URL requests with attached parameters that need to be redirected.

Use RewriteRule for all of your redirects and for all of your rewrites. Do not use Redirect or RedirectMatch here at all.

Fotiman

7:35 pm on Aug 9, 2011 (gmt 0)

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



Have not yet found the thread you mentioned, but I will keep searching. In the mean time, since this seems to be a regularly asked question, perhaps that thread should be pinned in this forum? Firing off a PM to the forum moderator now. :)