Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stop htaccess redirect

Tags:

php

.htaccess

I accessed a 'superfolder's .htaccess file and accidentally added

Rewrite / http://google.com/

This was done using php. Now I can't access php files in any directory to revert the change.

Is there anything I can do in a subdirectory of root to stop the redirect inside that folder?

Thank you.

And please don't ask more details about the 'accident'.. stupid mistake

like image 569
Matej Avatar asked Sep 27 '12 12:09

Matej


1 Answers

I contacted server admin, both laughed at it.. Still interesting though how to stop it redirecting although it shouldn't happen if I use mod_rewrite.

With mod_alias' Redirect, you're screwed. That directive is applied across the board, starting from the path-node where the htaccess file sits (if it's in an htaccess file), or the path-node of the <Directory> block that it sits in. So the only solution is to get an admin to remove it.

With mod_rewrite however, with an htaccess file, it doesn't act the same as within a <Directory> block. Rules inside an htaccess file in a path-node inside a directory has precedence over rules inside an htaccess file in the parent directory. So if you had 2 htaccess files:

/.htaccess:

RewriteEngine On
RewriteRule ^/? http://google.com/

and in /tmp/.htaccess:

RewriteEngine On
RewriteRule ^/?tmp/ http://stackoverflow.com/

And you go to http://yourdomain.com/tmp/, you'll get redirected to http://stackoverflow.com/ because the rules in the tmp directory has precedence over the rules in the parent directory. In face, the rules in the parent directory aren't applied at all unless you've used the RewriteOptions Inherit directive to inherit any rules from the parent directory.

Because of this, you can simply create an htaccess file with the following:

RewriteEngine On

Use FTP to upload it to your subdirectory, and upload the php file that you used to change the parent directory's htaccess file. Then just use your browser and go to that php file in the subdirectory.

Having simply turned on the rewrite engine in your subdirectory, without any rules, means:

  1. I have mod_rewrite active in this directory
  2. Since the rewrite engine is turned on in this directory, ignore all rules in the all parent directories.
  3. Since the mod_rewrite ruleset is blank (no actual RerwiteRule's) nothing happens at all
  4. Accessing this directory, eventhough the rewrite engine is on, mod_rewrite does nothing so it's as if the rewrite engine is turned off.

Sounds counter-intuitive, but that's just how it works.

like image 136
Jon Lin Avatar answered Sep 20 '22 05:09

Jon Lin