[英]Regexp with mod_rewrite
I spend about one hour, and read many tutorial ( MDN , Blogs.), 我花了大约一个小时,并阅读了许多教程( MDN ,博客),
still can't finger it out, and this is what I want to get: 仍然无法指出,这就是我想要得到的:
http://localhost/post/create
http://localhost/post/create/
http://localhost/post/create/?ID=123
the real path is: 真正的路径是:
http://localhost/includes/function/post/create.php
so I tried: 所以我尝试了:
RewriteRule ^post/(.*)(/.*)?$ includes/function/post/$1.php$2
It looks fine but it won't work if the URL is end with '/' or '/?ID=123' , 看起来不错,但如果URL以'/'或'/?ID = 123'结尾,则无法使用 ,
and sometimes it just get more worse just throw me an HTTP 500 error, 有时情况变得更糟,只是向我抛出HTTP 500错误,
any solution please? 有什么解决办法吗?
edit: I hope that I can use the above three ways with only one rule, is it possible? 编辑:我希望我可以只使用一条规则就可以使用上述三种方式,这可能吗?
edit2: I realize that I just need to remove -MultiView
in my .htaccess edit2:我意识到我只需要删除.htaccess中的
-MultiView
You can use this rule in your root .htaccess: 您可以在根.htaccess中使用此规则:
RewriteEngine On
RewriteRule ^post/([^/]+)/?$ /includes/function/post/$1.php [L,QSA]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.