Chalaka Ellawala Chalaka Ellawala - 2 months ago 11
Apache Configuration Question

htaccess redirect from one port to another

I have want to redirect urls that contains ?_escaped_fragment_= to another port. For an example,

http://localhost:8080/web/?_escaped_fragment_=/privacy


to

http://localhost:8082/web/?_escaped_fragment_=/privacy


My current htaccess is as below.

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=/?(.*)$
RewriteRule ^(.*)$ http://dev.dermveda.com:8082/$1 [r=301,nc]


The issue is, if the URL contains
web/
, it doesnt redirect to my new port. But if it doesnt have
web/
it redirects fine.
e.g.
URLs like
http://localhost:8080/web/?_escaped_fragment_=/privacy
are not redirected. But URLs like
http://localhost:8080/?_escaped_fragment_=/privacy
are redirected. My question is, How should I implement htaccess to redirect URLs with
web/
to another port.

Answer

Problem is presence of this condition:

RewriteCond %{REQUEST_URI}  ^/$

This condition means redirect only if your URL is /, which means only landing match.

Just remove that condition and have your rule as:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^_escaped_fragment_= [NC]
RewriteRule ^ http://dev.dermveda.com:8082%{REQUEST_URI} [R=301,L,NE]