如何写的.htaccess重定向像计算器的确为它的问题它的、计算器、重定向、如何写

2023-09-02 00:39:13 作者:打断一切,不回忆

我想写一个htaccess的规则,将重定向有人要求

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

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

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]

任何帮助是非常AP preciated。

Any help is much appreciated.

推荐答案

重写规则^ HTTP://([^ /] *)/问题/( d +)/(。*)$ HTTP :?//$1/questions/question_handler.php QID = $ 2

(。*)可能是太贪婪所以它使用的 http://mysite.com/questions/123/my-question-name 作为匹配的第一组

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