Reputation: 5291
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
.
http://mydomain.com/123
.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.
Upvotes: 1
Views: 1343
Reputation: 360702
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.
Upvotes: 4