Welcome,
for a long time I'm struggling with the problem of redirecting the url to a separate url in case the a special baerer token is given, I don't want to change any parameter just make a match and send this match to another url.
My setup is apache 2.4.41
typical request from postman:
https://xxxdddyyy.dqco1.firma-online.com/rest/auto-com/complete_addr?in_country=FR&in_line=73 avenue des lilas&access_token=988738467
the redirection should be like this:
http://tomcat-local:10022/rest/auto-com/complete_addr?in_country=FR&in_line=73 avenue des lilas&access_token=988738467
What I've tried so far in apache2.conf
RewriteCond %{QUERY_STRING} ^access_token=(988738467)$
RewriteRule (.*) http://tomcat-local:10022/ [R=301,L]
The goal is that a client with a specific token will be served by a specific tomcat server
Please help me, maybe I'm doing something wrong, I tried also RedirectMatch, unfortunately without success, all regexes I tested on https://regex101.com/
EDIT:
Still Nothing,I don't understand what's wrong. My config
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)access_token=988738467($|&)
RewriteRule ^(.*)$ http://tomcat-local:10022/$1 [QSA,P,L]
</IfModule>
# disable some HTTP request types for security reasons
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD|OPTIONS)$
RewriteRule .* - [F]
</IfModule>
Access_log :
"GET /rest/auto-com/complete_addr?in_country=FR&in_line=73%20avenue%20des%20lilas&access_token=988738467 HTTP/1.1" "complete_addr" 200 200 1225 "-" "PostmanRuntime/7.28.4"
Solved
RewriteEngine On
RewriteOptions InheritDown
RewriteCond %{QUERY_STRING} (^|&)access_token=988738467($|&)
RewriteRule ^(.*)$ http://tomcat-local:10022/$1 [QSA,P,L]
# disable some HTTP request types for security reasons
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]
RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD|OPTIONS)$
RewriteRule .* - [F]
Greetings Paul
https://xxxdddyyy.dqco1.firma-online.com/rest/auto-com/complete_addr?in_country=FR&in_line=73 avenue des lilas&access_token=988738467in your browser? And you want it to redirect/change it to URLhttp://tomcat-local:10022/? Thank you.https://xxxdddyyy.dqco1.firma-online.com/rest/auto-com/complete_addr?in_country=(.*)&in_line=(.*)&access_token=988738467this is what it should look like from a regex perspective all this should be redirect tohttp://tomcat-local:10022/rest/auto-com/complete_addr?in_country=$1&in_line=$2&access_token=988738467https://xxxdddyyy.dqco1.firma-online.com/rest/auto-com/complete_addr?in_country=(.*)&in_line=(.*)&access_token=988738467How to catch only a match on a specific baerer token and forward the whole request. The goal is that a client with a specific token will be served by a specific tomcat server.http://localhost:80/test?test_blablaand you want it to change tohttp://localhost:80/testetc.