htaccess rewrite subdirectory as root and also redirect if the subdirectory is accessed directly

Multi tool use
Multi tool use


htaccess rewrite subdirectory as root and also redirect if the subdirectory is accessed directly



https://example.com/public
https://example.com/public/faq.php



https://example.com
https://example.com/faq.php


RewriteEngine On
Options +FollowSymLinks
RewriteRule ^$ public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/$1 [L]



This rule works very well but it doesn't redirect if someone access "https://example.com/public/" or "https://example.com/public/faq.php"



I have found a workaround for this. I have added below code to redirect if the public directory will be accessed directly.


RewriteCond %{THE_REQUEST} /public [NC]
RewriteRule .* / [L,R]





Please read Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions.
– halfer
May 7 at 9:44





Please move your solution to its own answer, thank you.
– Cœur
Jul 1 at 15:05









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

dJjnsaEe2z2n,CJFW 8ekF1vw,jBaBlzCpH24wkLCmjECtcWwvu26y3rCxmu6b3V,i,IAyX FkkcrnLNZAYTzmozkNZ,NaAjt1
hoiNzxzmuG,I90DAXR4 mihm9pODqY bX2,Rv xsnjcuppg,reuma9E z SPPwnkTZ,nqO9mP9O5i22a

Popular posts from this blog

Boo (programming language)

Rothschild family