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]
此规则运作良好但如果有人访问" https://example.com/public/"它不会重定向。或" https://example.com/public/faq.php"
我找到了解决方法。如果直接访问公共目录,我已添加以下代码重定向。
RewriteCond %{THE_REQUEST} /public [NC]
RewriteRule .* / [L,R]