Question

I've been trying inerhiting my rules with RewriteOptions Inerhit, because for some reason rules are not inerhited by default.You might want to know that I'm on a LiteSpeed server.

The IP XXX.XX.XX.XX points to a subdomain which is located in ~/public_html/dir/sub/

This .htaccess is located in ~/public_html/:

RewriteEngine On
RewriteOptions Inherit

RewriteCond %{HTTP_HOST} ^XXX.XX.XX.XX$ [NC]
RewriteRule ^(.*)$ http://www.example.com [R=301,L]

In ~/public_html/dir/ I have this .htaccess:

RewriteEngine On
RewriteOptions Inherit

And in ~/public_html/dir/sub/ the .htaccess also looks like this:

RewriteEngine On
RewriteOptions Inherit

In this .htaccess there's also some WordPress code below which I also tried to remove but nothing changed.

I also tried to use RewriteOptions Inherit Before but rules from ~/public_html/ are not applied. So if I go to the IP I'm not redirected.

Anyone faced such a problem before and got any tips for me what I cloud try? I really did a lot of search but couldn't figure out what's wrong.

Was it helpful?

Solution

I found out that inherited (in root folder) rules are parsed with the subdirectory context

/.htaccess
RewriteRule melon http://www.google.com [R,L]
RewriteRule /services/bar http://www.yahoo.com [R,L]

/services/.htaccess
RewriteEngine On
RewriteOptions Inherit
deny from all

http://mydomin.com/services/bar => 403
http://mydomin.com/services/melon => google.com !!!

Maybe try with a more loose RewriteRule (.*)

Also, as RewriteRule context is lost, try using RewriteCond capture pattern if you need conditionnal rewrite

RewriteCond %{REQUEST_URI} (/services/.*)
RewriteRule (.*) http://elsewhere.com/%1 
#in place of a basic RewriteRule /services/(.*) http://elsewhere.com/$1 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top