Get up to 80 % extra points for free! More info:

Discussion: .htaccess

In the previous quiz, Online PHP Quiz, we tested our experience gained from the course.

Activities
Avatar

Member
Avatar
:4/13/2017 15:55

I'm building my own MVC framework. Everything works except one error in console(GET http://my-domain.com/ 403 (Forbidden)). It's caused because it tried to find index.php in document root. Why it keeps searching index.php in document root when i wrote this in .htaccess(which is in doc root):

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(css|js|icon|zip|rar|png|jpg|gif|pdf)$ public/bootstrap.php [L]

When I add index.php to doc root the error is gone but it shows the doc root index.php... I tried to redirect from index.php to my bootstrap.php file in public directory and it worked - all showed up like it had to, no errors in console But the php redirect slows down page. So the question is - why the f*ck is browser still searching for index.php, when I said to rewrite all requests to public/bootstrap­.php??
Thanks

 
Reply
4/13/2017 15:55
Avatar
Replies to
David Capka Hartinger:4/14/2017 5:14

This is usually done by using 2 .htaccess files. One for your root folder:

<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^$ public/ [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} !^public/
        RewriteRule ^(.*)$ public/$1
</IfModule>

And the second one for the public folder:

Options -Indexes

RewriteEngine On
# RewriteBase /

# front controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz)$ index.php [L]

AddType application/x-httpd-php .php .phtml

This should work.

Up Reply
4/14/2017 5:14
You can walk through a storm and feel the wind but you know you are not the wind.
Avatar

Member
Avatar
Replies to David Capka Hartinger
:4/14/2017 8:55

Yep, thanks.

 
Up Reply
4/14/2017 8:55
To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

3 messages from 3 displayed.