3
votes

I'm trying to write a .htaccess rule that would redirect someone asking for

http://mysite.com/questions/123/my-question-name

to

http://mysite.com/questions/question_handler.php?qid=123

Here's what i wrote so far (it's not working):

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?(.*)$ [NC]
RewriteRule ^(.*)/questions/(\d+)/(.*)$ http://%1/questions/question_handler.php?qid=%2$1 [R=301,L]

Any help is much appreciated.

2

2 Answers

4
votes

RewriteRule ^http://([^/]*)/questions/(\d+)/(.*)$ http://$1/questions/question_handler.php?qid=$2

Your (.*) was probably too greedy so it was using http://mysite.com/questions/123/my-question-name as the first group matched

2
votes

I would do something like this

RewriteEngine on
RewriteRule ^questions/([0-9]+)/?$ questions/question_handler.php?qid=$1 [NC,L]