Release access to page 404.html with .htaccess

3

I'm having a problem while trying to free access to page 404.html through my .htaccess, I always give Internal Server Error. How do I enforce a rule for only 404.html to be released for direct access?

.htaccess:

Options -Indexes
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]

RewriteRule ^([^/]*)$ index.php?page=$1 [L]
RewriteRule ^([^/]*)/([^/]*)$ index.php?page=$1&sub=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ index.php?page=$1&sub=$2&id=$3 [L]

<Files *.php>
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</Files>

<Files index.php>
    Order Allow,Deny
    Allow from all
</Files>
    
asked by anonymous 19.02.2014 / 19:03

1 answer

7

You can try as follows:

Options -Indexes
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/]*)$ index.php?page=$1 [L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)$ index.php?page=$1&sub=$2 [L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ index.php?page=$1&sub=$2&id=$3 [L]

<Files *.php>
   Order Deny,Allow
   Deny from all
   Allow from 127.0.0.1
</Files>

<Files index.php>
   Order Allow,Deny
   Allow from all
</Files>

By deleting the RewriteRule ^.*$ initial, to only redirect if the corresponding file does not exist (remembering that each set of RewriteCond s only applies to RewriteRule following).

See more in this answer:

Rewrite URL for root access but not block subdomain access

    
19.02.2014 / 19:09