homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

RewriteRule for .asp?QueryString=123 to .php.
I am shocking with these things :o(

 10:21 am on May 3, 2011 (gmt 0)

I have just migrated my site from ASP to PHP, and wonder how I could simply rewrite the old .asp links to call the .php file.

The old links looked like this


should all result in

I know it goes into .htaccess
and starts with:
Options +FollowSymLinks
RewriteEngine on

Thanks in advance...



 10:24 am on May 3, 2011 (gmt 0)

Should these be silently rewritten or say 301?

The end game is to 'extinct' the .asp requests...


 8:22 pm on May 3, 2011 (gmt 0)

You have new PHP files.

Do you want to continue using the old URLs? This is entirely possible by using an internal rewrite.

Do you have new URLs? You can redirect requests for old URLs to the new URLs by using a redirect.

Both bits of code would use a RewriteRule. A redirect would include the domain name and use the [R=301,L] flags. A rewrite would not include any domain name and use only the [L] flag.

RewriteRule cannot see query string data. You need a preceding RewriteCond looking at QUERY_STRING to see that data.


 9:44 pm on May 3, 2011 (gmt 0)

I probably forgot to say: While I understand somewhat (not really) the principle of it, I have not clue how to actually write the rules.
This is what I think it could be?

RewriteCond %{QUERY_STRING} val
RewriteRule ^/show.asp /

I am bit slow with the uptake; right now I want to fix the 404 I am getting when I get requests for show.asp[?blah=122]

I will eventually tackle the "nice URIs".


 9:51 pm on May 3, 2011 (gmt 0)

There were two questions in the previous post.

Without answers there can be no code, because the specifications page of the project will be blank.


 10:04 pm on May 3, 2011 (gmt 0)

I tried this:
RewriteEngine on
RewriteRule ^show\.asp$ / [L]

... and it works... :)
One can enter show.asp?topic=123
this link stays in the browser, but it serves /?topic-123

The remaining question:
a) is it better to issue a 301 and rewrite the URI so that the browser changes to /?topic=123


 10:12 pm on May 3, 2011 (gmt 0)

I asked two questions several posts back.

They remain unanswered. I cannot comment on your code until I know what it is supposed to be doing.

It is quite likely you are heading in entirely the wrong direction.


 10:53 pm on May 3, 2011 (gmt 0)

Firstly, I appreciate your reply... in fact, any help I can get.
Secondly, I have spent some 100 hours (in the past 10 days) rewriting and testing the last 20% of my code to change my website from ASP to PHP. It is now live and kicking... Woohoo :)

This means to me that any older issue is most likely not relevant any more. There was a 'canonical' issue that caused my page to drop off the Google index. This has turned around. I am back from only 78 links to 304 and climbing -- you should see my happy smile. :)

The conversion to PHP has some things handled differently.
I optimised and cleansed the code; now 10% leaner.
So the new site is virtually a new venture (same contents and behaviour though).

Some of my 404 behaviour / code is different.

While it still redirects pages "very_old_url" to "new_url", as in static URI "corrections", I have no handling of dynamic URIs (yet).
Hence, the new problem of show.asp?query=123 leading currently to a 404.

Since I am now on Apache, I can use rewrite rules.
My question was how do I get show.asp?blah=123 to be answered with contents rather than a 404.

I have figured it out with the above RewriteRule.

And here comes my ignorant part that probably annoys you: I did not look back what I posted before, because I got this new thing now :)

In case you referring to this post [webmasterworld.com...] -- for me this was a different problem...

Another kettle of fish is the art of rewriting URIs, friendly URIs, proper redirects, proper HTTP codes and all...
I am a programmer by necessity, not by occupation, hence, it takes a lot of research and learning (and making mistakes) before I can tackle a specific problem. Once it has been solved I won't touch it unless it is broken or technology has moved on. Hence, I might be fully across a specific problem now, ask me in a year and I have forgotten it all...


 10:58 pm on May 3, 2011 (gmt 0)

Now got it (I believe)...

Your questions were:
1. Do you want to continue using the old URLs? This is entirely possible by using an internal rewrite.

2. Do you have new URLs? You can redirect requests for old URLs to the new URLs by using a redirect.

I answered 1. myself... which is the quick fix I have applied, and which serves contents, but may not be the right approach from a good webmaster perspective.

While I am an amateur, I still want to do a good job / right thing :)

Your question 2. is probably the way I should be going and want to be going, as it appears to me this is the right approach.

So yes, this is where I still need help. :)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved