Home Htaccess rewrite rule causing Forbidden access
Reply: 0

Htaccess rewrite rule causing Forbidden access

user1681
1#
user1681 Published in April 22, 2018, 12:56 am

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>
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO