URL rewrite in Apache for POST/DELETE/PUT

天涯浪子 提交于 2019-12-20 05:47:09

问题


I have my url like this

http://10.243.123.1/v1/data/register

I want to redirect/rewrite this url to

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

i.e

1.should remove v1 and make https

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

What rule should in need to add in httpd.conf file..??

Whether rule goes to httpd.conf or .htacccess file?

Please share your thoughts


回答1:


Put this code in your DOCUMENT_ROOT/.htaccess file:

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]


来源:https://stackoverflow.com/questions/24322035/url-rewrite-in-apache-for-post-delete-put

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!