Coder Coder - 5 months ago 31
Apache Configuration Question

Replace some parts of url with htaccess

I want to replace some parts of url using htaccess.

I am using below code but i am getting 404 error.

RewriteRule ^/v1/surveys/login(.*)$ /oauth2/rest/token/$1 [R=301,L]


This is my url http://192.168.1.10/survey/api/v1/surveys/login and i want to

replace with http://192.168.1.10/survey/api/oauth2/rest/token

Answer Source

You can use this rule just below RewriteEngine On line:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/(survey/api)/v1/surveys/login(/.*)?$ [NC]
RewriteRule ^ /%1/oauth2/rest/token%2 [R=301,L,NE]

# rest of the rules go below this