在Apache中为POST / DELETE / PUT重写URL

时间:2014-06-20 07:25:14

标签: apache .htaccess https httpd.conf

我有这样的网址

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文件?

请分享您的想法

1 个答案:

答案 0 :(得分:2)

将此代码放入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]