Search code examples
.htaccesshttp-redirectsubdirectorypublic-html

How do not redirect to /public_html if request is equaled /abc/* for example?


There is such a structure of directories:

/public_html
/abc
.htaccess

Now all requests go to the folder /public_html. This is the code of .htaccess:

RewriteEngine on

RewriteCond %{REQUEST_URI} !public_html/
RewriteRule (.*) /public_html/$1 [L]

What should I do for that the requests like [the website address]/abc/* redirect to the folder /abc instead of /public_html?

Something like that:

example.com/* - go to /public_html

example.com/abc/* - go to /abc

Thanks! And I'm sorry for my English!


Solution

  • RewriteCond %{REQUEST_URI} !public_html/
    

    Means that you want to rewrite if the REQUEST_URI does not contain public_html/. So to make sure you are not rewriting a URI with abc/ you need another condition that says so add

    RewriteCond %{REQUEST_URI} !abc/
    

    after the first RewriteCond and it should work. Now you say that if it does not contain either abc/ or public_html/ rewrite the url.