1

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.

3
  • 1
    RewriteRule ^/([0-9]+)+ form.php?id=$1 Commented Aug 18, 2010 at 19:47
  • This is similar to this question Commented Aug 18, 2010 at 19:48
  • yes I didn't found when i was asking. Commented Aug 18, 2010 at 19:53

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.