/    Sign up×
Community /Pin to ProfileBookmark

"Issue" after migrating from ASP to PHP.

Hi,

I´ve migrated a website from ASP to PHP.

In order to keep the records/entries on Google and other search engines, I´d like to dinamically change, via htaccess, the extension.
Eg: when trying to reach someurl/file.ASP?parameter1=1&……. automatically process to someurl/file.PHP?parameter1=1&……. automatically

I can make it work without the parameters.

Could anyone help me make it work??

Thank you!!!

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@BoarsHellMar 16.2007 — you can do a htaccess rewrite but you should consider doing a 301 direct (search engines won't mind I have done it many times with commercial sites that never lost ranking).

but if you insist on the the rewrite here is the code you need...
[CODE]
RewriteEngine On
RewriteCond %{REQUEST_URI} !-s
RewriteRule ^file.ASP?(.*) file.php?$1 [NC]
[/CODE]
Copy linkTweet thisAlerts:
@jonitasauthorMar 16.2007 — Thank you very much.

I´ll try it today.

Do you think 301 direct is better? Can you please tell me how to do it?

Thanks again!
Copy linkTweet thisAlerts:
@jonitasauthorMar 16.2007 — I´ve tried doing

RewriteCond %{REQUEST_URI} !-s

RewriteRule ^file.ASP?(.*) file.php?$1 [NC]

Unfortunatelly it doesen´t seem to work: I get 404.

Could anyone help me?

Thanks!
Copy linkTweet thisAlerts:
@BoarsHellMar 17.2007 — Let me explain what this rule does...

[COLOR="DarkRed"]file.ASP?(.*)[/COLOR] This is the url you want to rewrite. So when someone types in a url in to their browser like... [COLOR="DarkRed"]www.yourdomain.com/file.ASP?$id=23[/COLOR] this url will be rewritten but if the user types [COLOR="DarkRed"]www.yourdomain.com/index.ASP$id=23[/COLOR] this url will not be rewritten. I forget if the [COLOR="DarkRed"].ASP[/COLOR] is case sensitive or not.

The [COLOR="DarkRed"](.*)[/COLOR] takes everything after the [COLOR="DarkRed"]?[/COLOR] and is put back into the rewrite where the [COLOR="DarkRed"]$1[/COLOR] is located (you can have more than one variable if needed). So the url [COLOR="DarkRed"]www.yourdomain.com/file.ASP?$id=23[/COLOR] gets rewritten by your rule and the server loads the page [COLOR="DarkRed"]file.php$id=23[/COLOR]. The [COLOR="DarkRed"][NC][/COLOR] makes it case insensitive. If you do not have a file called [COLOR="DarkRed"]file.php[/COLOR] you will receive a 404 error even if you do have a [COLOR="DarkRed"]file.ASP[/COLOR] page.

Now for the 301 redirect...

[CODE]redirect 301 /oldFolderName/oldFileName.ASP http://www.yourDomainName.com/newFolderName/newFileName.php[/CODE]
Copy linkTweet thisAlerts:
@bokehMar 17.2007 — If all you are looking to do is replace the extension just do this:[CODE]RewriteRule ^(.*).asp$ $1.php [QSA][/CODE][B]Note:[/B] that is lower case.
Copy linkTweet thisAlerts:
@bokehMar 17.2007 — Sorry I'm not paying attention. To add the permanant redirect:[CODE]RewriteEngine On
RewriteRule ^(.*).asp$ http://%{HTTP_HOST}/$1.php [R=301,QSA][/CODE]
Personally a would quit using a file extension altogether now so this doesn't happen again in the future.
×

Success!

Help @jonitas spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...