Free access to page 404.html with . htaccess

Asked

Viewed 689 times

3

I am having a problem when trying to free access to 404.html page through my . htaccess, always gives Internal Server Error. How should I apply a rule to only 404.html is 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>
  • Root, In the same index folder :D

  • My . htaccess blocks direct access to . html and . php files, only . jpg, . css, . js are released. I would like to free up access to . html files in general.

1 answer

7


You can try this way:

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>

eliminating the RewriteRule ^.*$ initial, to only redirect if there is no corresponding file (remembering that each set of RewriteCondonly goes to the RewriteRule next).

See more in this answer:

Rewrite URL for "root" accesses but do not block access to sub-domains

  • It worked, but the . php files were accessible, and I want to block.

  • It’s settled, thank you. I’ll take a look at the answer.

  • I tried the . php case, but I didn’t test it. See if it works, it’s important to keep the question and the answer in order, as this can help other users.

  • It does not work this way, When using <Files> is normally blocking the files . php for access other than 127.0.0.1.

  • left with the files then.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.