我有这样的网址
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文件?
请分享您的想法
答案 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]