views:

35

answers:

1

Hi all. I have a webpage http://mydomain.com/form.php?id=123 , I need to keep this format for old functionality , and to implement a new functionality so the user could access this page like this http://mydomain.com/123.

  1. So the client will see this http://mydomain.com/123.
  2. And the server will understand as old version http://mydomain.com/form.php?id=123.

So this way I don't have to change the old functionality. I know that this can be accomplished through HTaccess rule. but don't know how. Please help. Thanks.

+2  A: 

This should probably handle it for you

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ form.php?q=$1 [L,QSA]

!-f excludes any files which already exist (so hitting /form.php directly will not get rewritten), !-d excludes any directories which exist (so if you have a real /123/ on your site it won't get rewritten), and otherwise redirects everything else to your form.php script.

If you only want to redirect purely numeric URLS, then mhitza's comment above is what you want.

Marc B