views:

33

answers:

1

hi i want something like this when user write www.test.com/6
in the behind it will go to http://www.test.com/index.php?id=6 but this is not redirection it will be mod_rewrite

i do something like this but i get internal server error

Options +FollowSymLinks RewriteEngine on RewriteRule ([0-9]*)$ /index.php?id=$1 [L,NC]

+1  A: 

I've written a very similar mod_rewrite line for one of my own projects. The regex could probably use some polishing, but it works, so here it is anyway:

RewriteRule ^([0-9]+)(/)?$ /path/to/file.php?id=$1 [QSA]
Fraxtil
thanks it works great =)
deep_walker
I'm not too familiar with mod_rewrite but `\d` is the same as `[0-9]` in regex, and you likely don't need to capture the slash so it doesn't need to be in a group. So you could probably use a regex like `^(\d+)/?$`.
Lèse majesté
now when i did like test.com/8/ it doesn't work how can i correct this ?it only works like test.com/8
deep_walker
It should work with the trailing slash; that's the purpose of `(/)?`. Perhaps try removing the parentheses, as Lèse majesté suggested.
Fraxtil