如何写的.htaccess重定向像计算器的确为它的问题 [英] how to write a .htaccess redirect like stackoverflow does for its questions
本文介绍了如何写的.htaccess重定向像计算器的确为它的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想写一个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
这篇关于如何写的.htaccess重定向像计算器的确为它的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文