Closed Thread Icon

Topic awaiting preservation: Moving a site from ASP -> PHP - redirection question... (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=30187" title="Pages that link to Topic awaiting preservation: Moving a site from ASP -&amp;gt; PHP - redirection question... (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Moving a site from ASP -&gt; PHP - redirection question... <span class="small">(Page 1 of 1)</span>\

 
flavoredair
Obsessive-Compulsive (I) Inmate

From: Washington, DC
Insane since: Apr 2008

posted posted 04-09-2008 18:39

For a little over five years, I've been running a blog that has become fairly successful and has attracted a nice base of around 5,000-7,000 regular unique readers who visit the site on a weekly basis. The site was originally made in ASP 3.0 since, at the time, that was really all I'd ever worked in as far as programming languages were concerned. Since then, I've picked up C#.Net and php and I feel it's time for a change.

Obviously I could just start fresh and rebuild the site in php with no problem, but the one big issue I have is that when I switch over to php, whenever someone comes to the site via a search engine or bookmarked link, they'll get a 404 because it's pointing to a .asp file instead of the new .php file. I'd prefer that not happen.

I recall reading something a year or two ago about a specific modification to .htaccess files that would create a general redirect for people from .asp to .php and other similar file extension changes, but I can't seem to find anything that explains how to do that and I would very much appreciate your help.

Thanks in advance.

- Scott

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana
Insane since: Aug 2000

posted posted 04-09-2008 19:52

What you want is called mod_rewrite. You can find documentation about it at apache.org.

Basically you will need two lines to do what you want. I'm writing this off the top of my head so it may not be exactly correct, but something like

RewriteEngine On
RewriteCond ${REQUEST_URI} \.asp$
RewriteRule (.*)\.asp$ $1.asp [L]

That should get you started. If you have any questions about the syntax, be sure to ask.

.



-- not necessarily stoned... just beautiful.

flavoredair
Obsessive-Compulsive (I) Inmate

From: Washington, DC
Insane since: Apr 2008

posted posted 04-09-2008 22:09
quote:

hyperbole said:

RewriteEngine On
RewriteCond ${REQUEST_URI} \.asp$
RewriteRule (.*)\.asp$ $1.asp [L]



Is that syntax right on the third line? Shouldn't it be:

RewriteRule (.*)\.php$ $1.php [L]

I could be wrong, though. Thanks for the info.

- Scott

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana
Insane since: Aug 2000

posted posted 04-10-2008 05:44

I'm sorry, I wrote it wrong. It should be

code:
RewriteRule (.*)\.asp$ $1.php [L]



What that line says is anytime the server sees a url that ends with \.asp change the url to a *.php file with the same name. I'm assuming that when you convert the site from .ASP to .PHP you will be converting it page-for-page. If that is not the case, you can add other Rewrite Rules to catch those differences.

For example, let's say you have a file named 'this.asp' that generates a page and you replace it with a page called 'that.php'.When someone finds the old link using a search engine, you want them to see the same content, but the search engine will send them to '.../this.asp' so you add a Rewrite rule that will change '.../this.asp' to '.../that.php'.

You can do that like this

code:
RewriteEngine On
RewriteCond ${REQUEST_URI} this.asp
RewriteRule (.*)this.asp $1that.php [L]
RewriteCond ${REQUEST_URI} \.asp$
RewriteRule (.*)\.asp$ $1.php [L]



note that the first rule will change '.../this.asp' to '.../that.php' and the second rule will change all other *.asp links to *.php.

I would recommend you read the link I gave above before adding these to your .htaccess file. I don't ever change the .htaccess file without looking up what I want to do in the manual. It's just too easy to disable your whole site if you make a mistake.

.



-- not necessarily stoned... just beautiful.

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 04-10-2008 09:30

Keep in mind you'd be stupid to develop a blog from scratch.
Seriously, there are any number of decent blog systems out there (though wordpress does have a tendency
to have a security flaw discovered every once in a while).

Nevertheless, mod_rewrite will help you migrating your urls.
Urls should never break.

Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 04-10-2008 10:42
quote:

Tyberius Prime said:

Keep in mind you'd be stupid to develop a blog from scratch. Seriously, there are any number of decent blog systems out there (though wordpress does have a tendencyto have a security flaw discovered every once in a while).



Woohoo! I'm stupid!


___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup

« BackwardsOnwards »

Show Forum Drop Down Menu