Redirect Without changing URL Apache

By | December 11, 2017
Questions:

I want to redirect one URL to another without changing the Browser URL

www.example.com/abc/(.*).xml should redirect to www.example.com/abc/xyz/index.htm?file=$1

But the Browser should display www.example.com/abc/(.*).xml

Answers:

You can use a RewriteRule:

RewriteEngine On
RewriteRule /abc/(.*)\.xml$ /abc/xyz/index.htm?file=$1 [L]

Make sure you have mod_rewrite enabled and put this either in your VirtualHost config, or in a .htaccess file in your DocumentRoot

Questions:
Answers:

As Constantine posted on the accepted solution, the [P] flag is dangerous as it converts the server as a proxy.

See [this]: https://serverfault.com/questions/214512/redirect-change-urls-or-redirect-http-to-https-in-apache-everything-you-ever?noredirect=1&lq=1

P = Proxy. Forces the rule to be handled by mod_proxy. Transparently provide content from other servers, because your web-server fetches it and re-serves it. This is a dangerous flag, as a poorly written one will turn your web-server into an open-proxy and That is Bad.

Leave a Reply

Your email address will not be published. Required fields are marked *