Welcome Guest, Not a member yet? Register   Sign In
index.php .htaccess trick won't work
#11

[eluser]daniels[/eluser]
My first RewriteRule checks if REQUEST_URI is /index.php* or /public* or /robots.txt or /favicon.ico
So only this files(index.php, robots.txt, favicon.ico) and path (/public) can be accessed from the web.
If for example i have a folder /uploads that won't be accessible as it does not match the rewrite rule.
If the request was not made to any of this files then it gets rewritten to index.php as it sure is something that shouldn't be accessible from the web or is a route, controller, etc which should be handled by the application. So in this case no need for second rewrite rule, just rewrite it to the application. (No extra checks, the apache doesn't even get to the second rule)

If it has got to the second rule, it means that the request was made for either /robots.txt or /favicon.ico or /index.php or a file inside /public folder.
And if so then i just check if that file exists, if it does we show it if not we get the nice 404 page of our app.
Using only -f without -d also makes sure we only allow access to existing files and not folders, as we don;t need to allow a user to see the contents of /public/img for example. (Yes this can be made also using Options Indexes directives, but we would still have that -d check for nothing.)

Anyway this is how i see things and this is how i use it and for me it works perfectly.


And yea, i think the forward slash might be redundant by using RewriteBase. Didn't thought about that.

LE:

So i tried this as you said:
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_URI} !^(index\.php|public|robots\.txt|favicon\.ico)
    RewriteRule ^(.*)$ index.php/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
But i get Internal Server Error, doe too many redirects.

So currently for me it still works only the .htaccess that i posted in my first post.


Messages In This Thread
index.php .htaccess trick won't work - by El Forum - 02-08-2012, 02:00 PM
index.php .htaccess trick won't work - by El Forum - 02-08-2012, 03:07 PM
index.php .htaccess trick won't work - by El Forum - 02-08-2012, 06:21 PM
index.php .htaccess trick won't work - by El Forum - 02-08-2012, 11:06 PM
index.php .htaccess trick won't work - by El Forum - 02-08-2012, 11:25 PM
index.php .htaccess trick won't work - by El Forum - 02-08-2012, 11:56 PM
index.php .htaccess trick won't work - by El Forum - 02-09-2012, 01:25 AM
index.php .htaccess trick won't work - by El Forum - 02-09-2012, 01:43 AM
index.php .htaccess trick won't work - by El Forum - 02-09-2012, 01:50 AM
index.php .htaccess trick won't work - by El Forum - 02-09-2012, 01:53 AM
index.php .htaccess trick won't work - by El Forum - 02-09-2012, 02:09 AM
index.php .htaccess trick won't work - by El Forum - 02-09-2012, 02:33 AM
index.php .htaccess trick won't work - by El Forum - 02-09-2012, 02:34 AM
index.php .htaccess trick won't work - by El Forum - 02-09-2012, 02:37 AM
index.php .htaccess trick won't work - by El Forum - 02-09-2012, 02:45 AM
index.php .htaccess trick won't work - by El Forum - 02-09-2012, 02:45 AM
index.php .htaccess trick won't work - by El Forum - 02-09-2012, 02:50 AM
index.php .htaccess trick won't work - by El Forum - 02-09-2012, 10:45 AM
index.php .htaccess trick won't work - by El Forum - 02-09-2012, 11:29 AM
index.php .htaccess trick won't work - by El Forum - 02-09-2012, 03:44 PM
index.php .htaccess trick won't work - by El Forum - 02-09-2012, 04:18 PM
index.php .htaccess trick won't work - by El Forum - 02-09-2012, 04:34 PM
index.php .htaccess trick won't work - by El Forum - 02-10-2012, 09:00 AM
index.php .htaccess trick won't work - by El Forum - 02-10-2012, 11:06 AM
index.php .htaccess trick won't work - by El Forum - 02-10-2012, 04:19 PM
index.php .htaccess trick won't work - by El Forum - 02-10-2012, 07:09 PM
index.php .htaccess trick won't work - by El Forum - 02-11-2012, 04:15 AM
index.php .htaccess trick won't work - by El Forum - 02-11-2012, 05:09 AM
index.php .htaccess trick won't work - by El Forum - 02-12-2012, 12:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB