Forum Moderators: phranque

Message Too Old, No Replies

301 Redirect

301 Redirect: From ASP to PHP with subdomains

         

andreasa2010

3:26 pm on Oct 17, 2010 (gmt 0)

10+ Year Member



Please help me! I have moved my entire site from ASP to PHP and need a 301 Redirect that will send the old asp-page to the new php-page (with the same name - except from the php-extension):

http://www.mysite.com/test.asp --> http://www.mysite.com/test.php


Needs also to work with virtual subdomains:

http://sub.mysite.com/test.asp --> http://sub.mysite.com/test.php


And default.asp should go to index.php:

http://www.mysite.com/folder/default.asp --> http://www.mysite.com/folder/index.php


Can someone please help me?

Thanks,

Andreasa

[edited by: andreasa2010 at 3:36 pm (utc) on Oct 17, 2010]

andreasa2010

3:31 pm on Oct 17, 2010 (gmt 0)

10+ Year Member



This is as fare as I reached (I don't know anything about .htaccess):

RedirectMatch (.*)default\.asp$ http://www.mysite.com$1index.php
RedirectMatch (.*)\.asp$ http://www.mysite.com$1.php


But it is not a 301 redirect and it doesn't catch subdomains.

[edited by: andreasa2010 at 3:36 pm (utc) on Oct 17, 2010]

jdMorgan

7:37 pm on Oct 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A better solution would be to leave your links and your URLs unchanged, and simply rewrite .asp URL requests to .php files.

Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine on
#
RewriteRule ^(.+)\.asp /$1.php [L]

This avoids having to change any of your URLs, making all users' bookmarks to your site obsolete, and possibly causing temporary (but possibly-long-term) damage to your pages' search rankings.

The idea here is that although you changed the "technology" of your site, there is no requirement or need to change any of your URLs at all. URLs are not filenames, and filenames are not URLs; They are different names for resources used in two different name-spaces: URLs "out there on the Web," and filepaths "here, inside the server." There is no problem at all with having the URL http://example.com/about-us.asp refer to the file /about.php

For best results, don't ever change a URL unless a judge says you have to.

Jim