how to write a .htaccess redirect like stackoverflow does for its questions

后端 未结 2 1653
别那么骄傲
别那么骄傲 2020-12-21 09:51

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         


        
相关标签:
2条回答
  • 2020-12-21 10:17

    I would do something like this

    RewriteEngine on
    RewriteRule ^questions/([0-9]+)/?$ questions/question_handler.php?qid=$1 [NC,L]
    
    0 讨论(0)
  • 2020-12-21 10:22

    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

    0 讨论(0)
提交回复
热议问题