Home Htaccess rewrite rule causing Forbidden access
Reply: 1

Htaccess rewrite rule causing Forbidden access

Ivan Lopes
1#
Ivan Lopes Published in 2017-12-03 12:07:10Z

I'm trying to hide subfolders from url like this:

localhost/imo/public_html/public/ajuda.php to 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.

this is my htaccess file:

<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. Any help at all would be very aprecciated.

Thank you.

UPDATE Thanks to @Matthijs Otterloo this is the working htaccess script:

<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>
Matthijs Otterloo
2#
Matthijs Otterloo Reply to 2017-12-03 12:18:03Z

Try something like this in your .htaccess file:

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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.31097 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO