Forum Moderators: phranque
Try -
Assuming that you are redirecting from example.com/somepage.asp -> example.com/articles/index.php?somepage
RewriteEngine On
RewriteRule (.*)\.asp$ /articles/index.php?$1 [R=301,L]
When testing you may want to use a 302 redirect, as if you use a 301 to test then your browser will cache the results and keep giving you the same permanent redirection even once you change your .htaccess rules. Once you have finished testing then change it to the 301, so you get the permanent redirect.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^.asp$ /articles/index.php [R=301,L,QSA]
</IfModule>
Jim
You can rewrite or redirect anything to anything as long as the requested URL contains all of the information needed to construct the new URL or filepath. That is, mod_rewrite can re-arrange the requested URL-path, can add fixed values to it, can remove parts of it, or do some or all of these in combination. What it cannot do is 'create' new unique information from nothing.
See the discussion of "back references" in the RewriteCond and RewriteRule documentation.
Jim
So I guess is my previous post possible and is there any example someone can show me?
Understand this: It is almost never a good thing to change a URL, and it is almost never necessary to change a URL. The only good reason to change a URL is because you are under a court order to change that URL -- for example, because you unknowingly violated someone's trademark.
Again, any URL can be mapped to any file on your server. You can move files into and out of subdiorectories, change from .cfm to .asp to .php, and never change a single link or URL on your site. If your site's filesstem and URL structure are well-organized, then this can be done very easily. If not, it may involve a rather long list of rewrite rules or a small script to do a translation database lookup, but it can almost always be done.
Here's a note from one of the two guys credited with inventing the hyperlinking concept that made the Web possible, Sir Tim Berners-Lee: Cool URIs don't change [w3.org].
I'd recommend that you take a step back from your plan, slow down, and take the time to learn what you actually need to do before committing to a plan which may give you cause to regret later.
Jim
Their new site will be a lot harder to maintain, and risks breakage at some point in the future when the purpose of all the redirects is forgotten (or someone overwrites them).