Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess proxy redirect for root and only root

I'm trying to redirect only the root domain (and not its subfolders) to another URL, without changing the address. I'm using .htaccess and redirecting with [P] flag, which works fine for subdirectories but not for the root.

When writing the following .htaccess everything works fine, but in 'regular' redirect and not proxy:

RewriteEngine on
Rewriterule ^$ http://mysubdomain.mydomain.com/ [R,L]

When changing to mod_proxy, it doesn't work (does not redirect without an error):

RewriteEngine on
Rewriterule ^$ http://mysubdomain.mydomain.com/ [P]

It is important to me to keep the original address in the browser address bar. any idea?

Thanks

like image 236
navotgil Avatar asked Feb 02 '26 17:02

navotgil


1 Answers

It's probably doesn't work because the rule doesn;t apply. In most cases the root is not empty, but contains a request to index.html or default.html . Give this snippet a try:

RewriteEngine  on
RewriteRule    "default.html"  "http://mysubdomain.mydomain.com/"  [P]
like image 177
Jonathan Saragossi Avatar answered Feb 05 '26 07:02

Jonathan Saragossi