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


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.

Popular posts from this blog

How to make file upload 'Required' in Contact Form 7?

Rothschild family

amazon EC2 - How to make wp-config.php to writable?