Skip to content

Commit cc56ea7

Browse files
Merge pull request #223 from paulmer/file-access-restrictions
Improved file access restrictions
2 parents 52991a9 + 73f1896 commit cc56ea7

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

.htaccess

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,62 @@ Options +FollowSymlinks
22

33
RewriteEngine On
44

5-
# Scalar pages have default views that are called when a URI has no file extension
6-
# Turn off the MultiView option (if it's on) so it doesn't conflict
5+
# Scalar pages have default views that are called when a URI has no
6+
# file extension Turn off the MultiView option (if it's on) so it
7+
# doesn't conflict
78
Options -MultiViews
89

910
# To route all requests to a maintenance page, uncomment these lines
10-
#RewriteCond %{REQUEST_FILENAME} !maintenance.html [NC]
11-
#RewriteRule (.*) maintenance.html [L]
12-
13-
# To route the home page (book index) to some place else, uncomment these lines
11+
#RewriteCond $1 !^maintenance.html$ [NC]
12+
#RewriteRule (.*) maintenance.html [R=503,L]
13+
14+
# To protect all hidden files and directories
15+
# (including, most importantly, .git)
16+
RewriteRule (^\.)|(/\.) - [R=404,L]
17+
18+
# Block any files in the root directory other
19+
# than codeigniter.php and maintenance.html
20+
RewriteCond ${REQUEST_FILENAME} -f
21+
RewriteCond $1 !maintenance.html$
22+
RewriteCond $1 !codeigniter.php$
23+
RewriteRule ^([^/]+)$ - [R=404,L]
24+
25+
# To route the home page (book index) to some place else, uncomment
26+
# these lines
1427
#RewriteCond %{REQUEST_FILENAME} ^/Library/WebServer/scalar\.usc\.edu/anvc/index\.php$
1528
#RewriteRule (.*) /Library/WebServer/scalar.usc.edu/anvc_site/ [L]
1629
#RewriteCond %{REQUEST_FILENAME} ^/Library/WebServer/scalar\.usc\.edu/anvc/$
1730
#RewriteRule (.*) /Library/WebServer/scalar.usc.edu/anvc_site/ [L]
1831

19-
# If your server is running SSL, uncomment these lines to force all requests through https
32+
# If your server is running SSL, uncomment these lines to force all
33+
# requests through https
2034
#RewriteCond %{SERVER_PORT} 80
2135
#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
2236

23-
# To protect against malicious file uploads (e.g., PHP files) uncomment these lines
24-
# and make sure to set "/scalar" in the second line to the path to your Scalar install
37+
# To protect against malicious file uploads (e.g., PHP files)
38+
# uncomment these lines
2539
#RewriteCond %{REQUEST_FILENAME} -f
26-
#RewriteCond %{REQUEST_URI} !^/scalar/system(.*) [NC]
27-
#RewriteCond %{REQUEST_FILENAME} !codeigniter.php [NC]
2840
#RewriteCond %{REQUEST_FILENAME} (\.php)$ [NC]
29-
#RewriteRule ^(.*)$ - [R=404,L]
41+
#RewriteCond $1 !^system/(.*) [NC]
42+
#RewriteCond $1 !^codeigniter.php(/.*)?$ [NC]
43+
#RewriteRule (.*) - [R=404,L]
3044

31-
# To route to an alternative file uploads path (e.g. "uploads" directory) uncomment these lines
32-
# or change to the desired location. This should match the localDir specified in local_settings.php
33-
#RewriteCond "%{DOCUMENT_ROOT}/uploads/%{REQUEST_URI}" -f
34-
#RewriteRule "^(.+)" "%{DOCUMENT_ROOT}/uploads/$1" [L]
45+
# To route to an alternative file uploads path (e.g. "uploads"
46+
# directory) uncomment these lines and change to the desired
47+
# location. This should match the localDir specified in
48+
# local_settings.php
49+
#RewriteCond "%{CONTEXT_DOCUMENT_ROOT}/uploads/$1" -f
50+
#RewriteRule (.+) "%{CONTEXT_DOCUMENT_ROOT}/uploads/$1" [L]
3551

3652
# Route to codeigniter if file or directory doesn't exist
37-
RewriteCond %{REQUEST_FILENAME} !codeigniter.php [NC]
53+
RewriteCond $1 !^codeigniter.php(/.*)?$ [NC]
3854
RewriteCond %{REQUEST_FILENAME} !-d
3955
RewriteCond %{REQUEST_FILENAME} !-f
4056
RewriteRule (.*) codeigniter.php/$1 [L]
4157
RewriteRule ^$ codeigniter.php [L]
4258

43-
# If a directory, don't send to codeigniter if it's the root folder
44-
# the server in turn will add the trailing slash and things are back to normal
45-
# This is to overcome what appears to be an old server setting on Vectors
46-
# and/or not being able to change DirectorySlash
47-
RewriteCond %{REQUEST_FILENAME} !codeigniter.php [NC]
48-
RewriteCond %{REQUEST_FILENAME} -d
49-
RewriteRule ^/(.*)$ - [L]
50-
5159
# Pass through directory
52-
RewriteCond %{REQUEST_FILENAME} !codeigniter.php [NC]
60+
RewriteCond $1 !^codeigniter.php(/.*)?$ [NC]
5361
RewriteCond %{REQUEST_FILENAME} -d
5462
RewriteRule (.*) codeigniter.php/$1 [L]
5563

0 commit comments

Comments
 (0)