重定向时维护 HTTP 方法类型
我在使用 .htaccess 重定向时遇到问题:
....
RewriteCond %{REQUEST_METHOD} ^GET
RewriteRule ^retweet/(.*)$ /test.php?method=get&path=$1
RewriteCond %{REQUEST_METHOD} ^PUT
RewriteRule ^retweet/(.*)$ /test.php?method=put&path=$1
RewriteCond %{REQUEST_METHOD} ^DELETE
RewriteRule ^retweet/(.*)$ /test.php?method=delete&path=$1
RewriteCond %{REQUEST_METHOD} ^POST
RewriteRule ^retweet/(.*)$ /test.php?method=get&path=$1
RewriteRule ^retweet/(.*)$ /test.php?method=null&path=$1
事实上,通过这种方式,我总是会获得 null 作为通过 PHP 捕获的匹配 HTTP 方法。我也尝试过使用这个更简单的解决方案:
RewriteRule ^(.*)$ /test.php?path=$1
但是,通过这种方式,它将始终返回“GET”PHP 方法。有什么解决办法吗? 谢谢。
I have a problem while using .htaccess redirection:
....
RewriteCond %{REQUEST_METHOD} ^GET
RewriteRule ^retweet/(.*)$ /test.php?method=get&path=$1
RewriteCond %{REQUEST_METHOD} ^PUT
RewriteRule ^retweet/(.*)$ /test.php?method=put&path=$1
RewriteCond %{REQUEST_METHOD} ^DELETE
RewriteRule ^retweet/(.*)$ /test.php?method=delete&path=$1
RewriteCond %{REQUEST_METHOD} ^POST
RewriteRule ^retweet/(.*)$ /test.php?method=get&path=$1
RewriteRule ^retweet/(.*)$ /test.php?method=null&path=$1
In fact, in this way, I'll always obtain null as matched HTTP method catched through PHP. I've tried also to use this simpler solution:
RewriteRule ^(.*)$ /test.php?path=$1
But, in this way, it will always return the "GET" PHP method. Is there any solution?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
干得好:
Here you go: