How to hide a rewrited URL in web browser - apache

I used Apache's mod_rewrite to redirect HTTP request to another server. I want to keep original URL in client's browser. Now it displayed rewrited URL in client's browser. The configuration as below in Httpd.conf file. Thank you advance.
RewriteEngine On
RewriteBase /tpiaccs/
RewriteRule /tpiaccs/uat/(.*) http:///tpiaccs/uat/$1 [NC,L]

If I recall correctly, by default it rewrites using external redirection (an implicit [R] flag) unless you specify otherwise.
This might do what you're after:
RewriteRule /tpiaccs/uat/(.*) http:///tpiaccs/uat/$1 [P,NC,L]
The P should make it internally proxy the request rather than doing an external redirect.
See https://httpd.apache.org/docs/trunk/rewrite/flags.html for details on the flags that can be used with URL rewriting.

Related

Apache rewrite path to paramater

How would i convert:
https://www.example.com/ja to redirect to https://www.example.com/?lng=ja
I've tried the apache rewrite rule:
RewriteRule ^ja$ /?lng=ja&%{QUERY_STRING}
but I just get a 404 when accessing https://www.example.com/ja
I've also tried:
RewriteRule ^ja$ /?lng=ja
Which just loads the home page with /ja but doesn't seem to add on the url param
Try RewriteRule ^ja$ /?lng=ja [R,L]
By default, mod_rewrite maps a URL to a filesystem path, but it can also be used to redirect one URL to another URL.
Use of the [R] flag causes a HTTP redirect to be issued to the browser. If a fully-qualified URL is specified (that is, including http://servername/) then a redirect will be issued to that location. Otherwise, the current protocol, servername, and port number will be used to generate the URL sent with the redirect.
You will almost always want to use [R] in conjunction with [L] (that is, use [R,L]) because on its own, the [R] flag prepends http://thishost[:thisport] to the URI, but then passes this on to the next rule in the ruleset, which can often result in 'Invalid URI in request' warnings.

Redirect all pages from old domain to new specific URL without trailing slash content

I've got an old domain, let's say oldomain.com where I need to redirect all traffic to a specific URL, newdomain.com/path
While redirects from oldomain.com go perfectly, anything with content after the trailing slash will be copied over in the newdomain url structure causing 404's.
For example visiting: oldomain.com/somepage will result in newdomain.com/pathsomepage
What I'm looking for are some rewrite rules that will redirect any and all traffic from oldomain.com to newdomain.com/path without changing the specific "newdomain.com/path" URL.
I'm currently using the rules bellow which leads to the result above:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldomain.com
RewriteRule ^(.*) https://newdomain.com/path [P]
PS: the redirect is going to a Magento store.
You are trying to reverse-proxy in your directives (the P flag in the rewrite), but since you are describing a redirect... In the old virtualhost you just need to add a simple Redirect directive like this:
Redirect / https://newdomain.example.com/
This will Redirect all requests no matter how they are made to the new domain. Example GET /something will be redirected to https://newdomain.example.com/something
If you want the target to be a fixed destination like https://newdomain.example.com/path no matter what, use RedirectMatch instead:
RedirectMatch ^ https://newdomain.example.com/path

Redirect request to another domain with mod_rewrite

Is it possible in Apache to redirect a request from my domain: www.example.com/index.html to another domain http://www.other-domain.com/page/info as if I was directly visiting that page?
So the user shouldn;t notice anything. He should simply think he's visiting www.example.com, while apache serves back the content of http://www.other-domain.com/page/info.
This is because the other domain is the new server, and the users should be able to visit the old URL as well. Note, I dont want to do a 301 redirect.
I know this can be done with VirtualHost, but my web host doesn't allow me to use that. I can use mod_rewrite, so I'm hoping I can do the same trick with that.
Anyone any idea if t his is possible, and if so, how to do it?
RewriteEngine on
RewriteRule ^/index.html$ http://www.other-domain.com/page/info [PT]
Only way to achieve this is by enabling mod_proxy on www.example.com. Once mod_proxy and mod_rewrute are enabled place this rule in DocumentRoot/.htaccess of www.example.com:
RewriteEngine On
RewriteRule ^/?(index\.html)?$ http://www.other-domain.com/page/info [L,P]

Apache mod_rewrite links proxy

I want to make a proxy for external links with apache's mod_rewrite module.
I want it to redirect user from, ie http://stackoverflow.com/go/http://example.com/ to http://example.com/ where http://stackoverflow.com/ is my site's URL. So I added a rule to .htaccess file.
RewriteRule ^/go/http://(.+) http://$1 [R=302,L]
But it doesn't work at all. How to fix this?
I am not sure if Apache or the browser reduces // to /, but since it doesn't change the directory one of them reduces this to a single slash on my setup. That's why the second slash has a ? behind it in the rule below:
RewriteRule ^go/http://?(.*)$ http://$1 [R,L]
This will redirect the user to that domain.
This will rewrite all urls (without the beginning http://) to new complete URL. If you're gonna use https links also, you need something like the second rule.
RewriteRule ^go/(.*) http://$1 [R=302,L,QSA,NE]
RewriteRule ^gos/(.*) https://$1 [R=302,L,QSA,NE]
I also added the QSA if your need to include parameters

Apache redirection to sub domain

My website URL till now was as per this pattern https://www.xyz.com, from which i served both static and dynamic contents. https://www.xyz.com defaults to home page, https://www.xyz.com/static/index.html, and dynamic contents are served from https://www.xyz.com/dyna/login.jsp.
Recently I added an additional webserver and got sub domain registered from which I plan to serve static content through http URL scheme instead of https, and only serve dynamic pages from https URL. So, if user types https://www.xyz.com, should redirect to http://static.abc.com.
Webserver: Apache 2.x
My Queries are:
a. How to configure apache to redirect request on https://www.xyz.com to http://static.abc.com while ensuring that request to https://www.xyz.com/dyna/login.jsp does not get redirected?
Will this have any noticeable performance overhead?
b. If redirection from http to https and also launching http screen from https page lead to any security warning in this case?
Note that I do not intend to submit any data from http to https and vice versa, it will be just URL redirection or links.
c. How to make the redirection cacheable?
use .htaccess to define https://www.example.com/static/index.html as https://www.example.com/index.html
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain/static/index.html [NC]
RewriteRule ^(.*)$ domain/index.html$1 [L,R=301]