-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.htaccess
86 lines (69 loc) · 2.57 KB
/
.htaccess
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
AddDefaultCharset utf-8
DefaultLanguage en-US
AddType application/xhtml+xml .xhtml
# AddType text/xml .xhtml
DirectoryIndex index.shtml index.xhtml index.html index.cgi
# Secure htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
# Force SSL
SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "jac.pics"
# Custom error pages
ErrorDocument 401 /error.html
ErrorDocument 404 /error.html
ErrorDocument 500 /error.html
# Protect against DOS attacks by limiting file upload size
LimitRequestBody 10240000
# Clean URLs
# TODO: I think RewriteRule never contains query string, so [^?]+ could be just .+.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Skip all rules if normal file request.
# We need this first condition to exclude urls with a non-empty query string.
RewriteCond %{QUERY_STRING} !.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule . - [last]
# Force 301 on legacy params.
# Consider just marking as gone:
# RewriteRule ^jcdsee\.cgi - [gone,last]
# Redirect `pic` to single:
RewriteCond %{QUERY_STRING} pic=([^&]+)
RewriteRule ^jcdsee\.cgi /single%1? [redirect=301,last]
# Redirect `cur_url` to folder:
RewriteCond %{QUERY_STRING} cur_url=([^&]+)
RewriteRule ^jcdsee\.cgi %1? [redirect=301,last]
# Short 'go' URL redirect. See #29.
RewriteRule ^go/(.+)$ /jcdsee.cgi?go=$1 [last]
# DIRECTORY: Normalize directories to have trailing slash: /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ([^/])$ /$1/
# DIRECTORY: Captures any real directory paths under /pics/ and converts to parameters.
RewriteRule ^(pics[^?]*)/$ /jcdsee.cgi?pic_path=/$1/ [qsappend,last]
# Force trailing slash if there is no '.' in the final segment (meaning it ignores file names).
# This works most of the time, but will not catch directories with a '.' in the name.
# Would be better to use some RewriteBase magic to test for dir or file like above.
RewriteRule (.*/[^?.]+[^?/])$ /$1/ [redirect=301,last]
# Display modes
RewriteRule ^(single|thumb|slide|list)/([^?]+)$ /jcdsee.cgi?pic_path=/$2&display_mode=$1 [qsappend,last]
# /jcdsee/ DIRECTORY: Prevent file listing here.
RewriteRule ^jcdsee/$ / [redirect=301,last]
</IfModule>
# Protect Entire website:
AuthType Basic
AuthName "Password required"
AuthUserFile /###########/.htpasswd-pics
# Define exceptions:
<RequireAny>
<RequireAll>
Require expr %{REQUEST_URI} =~ m#^/(error_redirect.php|error.html|favicon.ico)$#
</RequireAll>
# OR
Require valid-user
</RequireAny>
# Redirect to https version of page:
ErrorDocument 403 /error_redirect.php