Block access to your .htaccess file

Started on the old forum in July 2011 · view the original in the archive · old links redirect here

7 replies · 1,188 views · started 15 years ago · 1 min read

7 participants
razzbee Developer · 130 posts #1

The following code will prevent user to access your .htaccess file. Also, you can block multiple file type as well.

secure htaccess file

<Files .htaccess> order allow,deny deny from all </Files>

prevent viewing of a specific file

<Files secretfile.jpg> order allow,deny deny from all </Files>

multiple file types

<FilesMatch ".(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$"> Order Allow,Deny Deny from all </FilesMatch>

albo0210 Newbie · 1 posts #2

this code insert on the .htaccess ???

shakil420 Developer · 125 posts #4

razzbe bro do u know .htaccess code that user can redirect ... url mysite.com/username ++> mysite.com/index.php?user=username

arnage Lead · 811 posts #5

Search for mod-rewrite, its solved hundreds times for pages and for users. 🙂

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
stefudj Newbie · 1 posts #6

Options +FollowSymlinks RewriteEngine On RewriteRule ^([a-zA-Z0-9_$-]+)$ index.php?user=$1

ogah Junior · 17 posts #7

razzbee wrote: The following code will prevent user to access your .htaccess file. Also, you can block multiple file type as well.

secure htaccess file

<Files .htaccess> order allow,deny deny from all </Files>

prevent viewing of a specific file

<Files secretfile.jpg> order allow,deny deny from all </Files>

multiple file types

<FilesMatch ".(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$"> Order Allow,Deny Deny from all </FilesMatch>

if already have this one: <FilesMatch ".(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$"> Order Allow,Deny Deny from all </FilesMatch>

this one is not necessary: <Files .htaccess> order allow,deny deny from all </Files>

razzbee Developer · 130 posts #8

ogah wrote: if already have this one: <FilesMatch ".(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$"> Order Allow,Deny Deny from all </FilesMatch>

this one is not necessary: <Files .htaccess> order allow,deny deny from all </Files>

FilesMatch uses Regex so its recommended U use the correct and recommended code even though that will work but escape the dot (.) the dot must be . so do this :

<FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
 Order Allow,Deny
 Deny from all
</FilesMatch>

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close