[英]Htaccess rewrite rule causing Forbidden access
I'm trying to hide subfolders from url like this: 我正在尝试从url隐藏子文件夹,如下所示:
localhost/imo/public_html/public/ajuda.php to localhost/imo/ajuda localhost / imo / public_html / public / ajuda.php到localhost / imo / ajuda
Its working well if the file exist, if not i get a forbidden access like this: 如果文件存在,它的运行良好,否则,我将被禁止访问:
You don't have permission to access /imo/public_html/public/public_html/public/public_html...public/contacto.php.php.php.php.php.php.php.php.php.php on this server.
您无权访问此服务器上的/imo/public_html/public/public_html/public/public_html...public/contacto.php.php.php.php.php.php.php.php.php.php.php。
this is my htaccess file: 这是我的htaccess文件:
<IfModule mod_rewrite.c>
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^$ public_html/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ public_html/public/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L,QSA,NC]
</IfModule>
I already search on stackoverflow and it seems that the rules is causing a loop but the solutions provided didn't work on my case so far. 我已经在stackoverflow上进行搜索,看来规则正在引起一个循环,但是到目前为止,所提供的解决方案在我的案例中仍然无效。 Any help at all would be very aprecciated.
任何帮助都将不胜感激。
Thank you. 谢谢。
UPDATE Thanks to @Matthijs Otterloo this is the working htaccess script: 更新感谢@Matthijs Otterloo,这是有效的htaccess脚本:
<IfModule mod_rewrite.c>
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^$ public_html/public/
RewriteCond %{REQUEST_URI} !^/public_html/public
RewriteRule ^/?([^/]+)$ /public_html/public/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L,QSA,NC]
</IfModule>
Try something like this in your .htaccess
file: 在您的
.htaccess
文件中尝试以下操作:
RewriteEngine On RewriteCond %{REQUEST_URI} !^/public_html/public RewriteRule ^/?([^/]+)$ /public_html/public/$1 [L]
Best way would be to set-up propper virtual hosts but this should fix it. 最好的方法是设置适当的虚拟主机,但这应该可以解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.