Forum Moderators: phranque

Message Too Old, No Replies

Rewrite an .asp file to a .php file

         

o0Corps0o

8:40 am on May 24, 2012 (gmt 0)

10+ Year Member



I don't know if this is possible to do via htaccess or if it has something to do with server settings.

But basically i would like something like this:

RewriteRule ^RenderMe\.asp$ http://www.example.com

our website is php based (joomla), where our old website was done using .asp and it has been added on many other sites as a link. So i'm wanting to redirect/rewrite this asp file to go to our main page.

Now- I have this higher up in my code, which works:

RewriteCond %{QUERY_STRING} ^linkid=001(.*)$
RewriteRule ^RenderMe\.asp$ http://www.example.com/example/?

This rewrites fine.

If anyone has any suggestions i would appreciate it.

lucy24

10:35 am on May 24, 2012 (gmt 0)

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



Yup. I suggest you spend some time reading earlier posts in this forum-- doesn't much matter which ones-- so you can get a solid grip on the difference between Rewrite and Redirect. As processes, not as names or modules.

Then start by saying what you would like to do. Don't jump straight into how you would like to do it, because then it becomes impossible to tell if you're going about it the right way.

RewriteCond %{QUERY_STRING} ^linkid=001(.*)$
RewriteRule ^RenderMe\.asp$ http://www.example.com/example/?

This rewrites fine.

You surprise me. I would have expected it to redirect, what with that protocol-and-domain in the target. But, again, since you haven't said exactly what the rule is intended to do, we'll have to take your word for it that it does it. Whatever it is :) Best guess:

"If the request is for example.com/RenderMe.asp with query string beginning 'linkid=001' and optionally containing more stuff, then issue a 302 redirect to the index page of the directory /example/ and strip away the query string. And then stay in mod_rewrite pending further instructions."

phranque

10:44 am on May 24, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



- the directive of each module will execute in the order encountered in the server config and .htaccess file(s).

- when you have several rewrites you must put the directives in order that the most specific rules are executed first.

- if you want to stop the rewrites after executing a specific rule you should use the [L] flag for that rule.

- if you specify the protocol and hostname in the target url then it will change an internal rewrite directive to an external redirect using a 302 status code.

- since you don't use the grouping in the RewriteCond there is no need to have that in the pattern nor the end anchor - so this should be sufficient:
RewriteCond %{QUERY_STRING} ^linkid=001


i would move the first rule after the 2nd.
as far as how you modify the rest that depends on what you are actually trying to accomplish with these rules.
do you want to keep referring to and serving the .asp urls or do you want to redirect to the new urls?