Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.5k views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...