I want to redirect all request of one particular domain to another, except for one page request. I hope my attempt explains what I try to do:
RewriteEngine on
Rewritecond %{HTTP_HOST} !^host.mysite.com
RewriteRule ^link/([^/]+)/([^/]+)/([^/]+)$ dokument_by_link.php?$1=1&document_type=$2&value=$3 [NC,L]
Rewritecond %{HTTP_HOST} !^host.mysite.com
RewriteCond %{REQUEST_URI} !^/link/
RewriteCond %{REQUEST_URI} !^dokument_by_link.php
RewriteRule (.*) https://www.anothersite.de/$1 [R=302,L]
#This should not apply to host.mysite.com, but I think this is already accomplished by the L-flag above
RewriteRule ^test/?$ test.php [L,NC]
host.mysite.com/link/ should be redirected to host.mysite.com/document_by_link.php
RewriteRule ^link/([^/]+)/([^/]+)/([^/]+)$ dokument_by_link.php?$1=1&document_type=$2&value=$3 [NC,L]
All other requests should be redirected to https://www.anothersite.de
Thank you very much!
2
Answers
This should do the trick :
This should work for you:
Using
THE_REQUEST
instead ofREQUEST_URI
here asREQUEST_URI
may change to a rewritten URI whereasTHE_REQUEST
remains same for the scope of a web request.THE_REQUEST
variable represents original request received by Apache from your browser and it doesn’t get overwritten after execution of other rewrite directives. Example value of this variable isGET /index.php?id=123 HTTP/1.1