【问题标题】:URL rewrite in Apache for POST/DELETE/PUT在 Apache 中为 POST/DELETE/PUT 重写 URL
【发布时间】:2014-08-10 21:39:46
【问题描述】:

我有这样的网址

http://10.243.123.1/v1/data/register

我想将此网址重定向/重写到

https://10.243.123.1/data/register  (This is HTTP POST/PUT/DELETE url)

1.should remove v1 and make https

2.If url does not contains v1 then just make https alone.

httpd.conf 文件中需要添加什么规则??

规则是转到 httpd.conf 还是 .htacccess 文件?

请分享你的想法

【问题讨论】:

    标签: apache .htaccess https httpd.conf


    【解决方案1】:

    将此代码放入您的DOCUMENT_ROOT/.htaccess 文件中:

    RewriteEngine On
    
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{THE_REQUEST} \s/+v1/(\S+) [NC]
    RewriteRule ^ https://%{HTTP_HOST}/%1? [R=302,L,NE]
    
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NE]
    
    RewriteRule !^v1/ /v1%{REQUEST_URI} [NC,L]
    

    【讨论】:

    • 感谢您的回复,收到此错误10.100.1.111/v1/data/messages

      HTTP 状态 405 - 不支持请求方法“GET”

      http 到 https 工作但 v1 消除不起作用。跨度>
    • 这绝对不是由这些规则生成的。您的 .htaccess 或 Apache 配置中是否还有其他规则?
    • 其实我的网址是POST请求。
    • POST 请求不应被外部重定向,否则它们会丢失 POST 数据。查看规则中的更改以避免从第一条规则发布。
    • 我所有的 API 都是 POST、DELETE 和 PUT,我希望对非 GET url 进行重定向,我怎样才能在不丢失 POST 数据的情况下实现..??我是新手,麻烦您了。。
    猜你喜欢
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-08
    • 1970-01-01
    • 2015-01-25
    • 1970-01-01
    • 2012-01-07
    • 2010-09-24
    相关资源
    最近更新 更多