forked from laukstein/ajax-seo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.htaccess
230 lines (194 loc) · 9.29 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# Without -MultiViews will be returned 404 error for a rewrite if a folder of the same name does not exist.
# For highest performance, and no symlink protection, set FollowSymLinks everywhere, and never set SymLinksIfOwnerMatch, http://httpd.apache.org/docs/current/misc/perf-tuning.html#symlinks
# With +IncludesNOEXEC server-side includes are permitted, but the #exec cmd and #exec cgi are disabled.
# It is still possible to #include virtual CGI scripts from ScriptAliase'd directories, httpd.apache.org/docs/trunk/mod/core.html
Options -MultiViews -SymLinksIfOwnerMatch +IncludesNOEXEC
# -Indexes will block users from browsing folders without a default document.
<IfModule mod_autoindex.c>
Options -Indexes
</IfModule>
ServerSignature Off
# DirectorySlash Off
# Security
# Uncomment php_flag and php_value if you are not able to apply config/php.ini on your server.
# php_flag allow_url_fopen 0
# php_flag allow_url_include 0
# php_flag display_errors 0
# php_flag expose_php 0
# php_flag log_errors 1
# php_flag session.use_trans_sid 0
# php_flag short_open_tag 0
# php_value error_log error_log.txt
# UTF-8 encoding
AddDefaultCharset utf-8
AddCharset utf-8 .css .js .json .txt .xml
# Proper MIME type
AddType application/javascript js
AddType application/json json
AddType application/vnd.ms-fontobject eot
AddType application/x-chrome-extension crx
AddType application/x-font-ttf ttf
AddType application/x-font-woff woff
AddType application/xml xml
AddType audio/ogg oga ogg
AddType font/opentype otf
AddType image/svg+xml svg
AddType image/webp webp
AddType image/x-icon ico
AddType text/cache-manifest appcache
AddType video/mp4 mp4
AddType video/ogg ogv
AddType video/webm webm
AddType video/x-flv flv
# Custom error pages
# ErrorDocument 403 "403 Forbidden"
# ErrorDocument 404 "404 Not Found"
# ErrorDocument 500 "500 Internal Server Error"
# Gzip compression
<IfModule mod_deflate.c>
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
BrowserMatch MSIE ie
Header set X-UA-Compatible "IE=edge,chrome=1" env=ie
Header set X-Content-Type-Options "nosniff" env=ie
Header set X-XSS-Protection "1; mode=block" env=ie
</IfModule>
</IfModule>
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE application/javascript \
application/json \
application/rss+xml \
application/vnd.ms-fontobject \
application/x-font-ttf \
application/xhtml+xml \
application/xml \
font/opentype \
image/svg+xml \
image/x-icon \
text/css \
text/html \
text/plain
</IfModule>
</IfModule>
# Expires headers (for better cache control)
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 week"
ExpiresByType text/cache-manifest "access plus 0 seconds"
ExpiresByType text/css "access plus 1 year"
ExpiresByType text/html "access plus 0 seconds"
ExpiresByType text/plain "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
</IfModule>
<IfModule mod_headers.c>
# Do not show a snippet in the search results for this files.
<FilesMatch "\.(css|js|json|txt|xml)$">
Header set X-Robots-Tag nosnippet
</FilesMatch>
# Allow Web Fonts access from all domains.
<FilesMatch "\.(woff|ttf|otf|eot)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
# Execute this files as PHP.
<FilesMatch "(humans.txt|robots.txt|sitemap.xml)">
SetHandler application/x-httpd-php
</FilesMatch>
Header unset ETag
</IfModule>
FileETag None
<IfModule mod_rewrite.c>
# FollowSymLinks must be enabled for turning on the rewrite engine.
Options FollowSymlinks
RewriteEngine On
# Handle HTTPS protocol.
RewriteCond %{HTTPS} on
RewriteRule .* - [env=https:s]
# Rewrite www to no-www domain.
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:https}://%1%{REQUEST_URI} [R=301,L]
# Avoid subdomains.
# RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
# RewriteRule ^(.*)$ http%{ENV:https}://domain.com/$1 [R=301,L]
# Rewrite multiple slashes with single slash after domain.
RewriteCond %{THE_REQUEST} ^[A-Z]+\s//+(.*)\sHTTP/[0-9.]+$ [OR]
RewriteCond %{THE_REQUEST} ^[A-Z]+\s(.*/)/+\sHTTP/[0-9.]+$
RewriteRule .* http%{ENV:https}://%{HTTP_HOST}/%1 [R=301,NE,L]
# Rewrite multiple slashes with single slash in URL.
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,NE,L]
# Remove slash from URL end.
RewriteCond %{REQUEST_URI} ^(.+)/$ [OR]
RewriteRule ^.+/$ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.+/$ %1 [R=301,L]
# Rewrite backslash with slash. Works on FF when applied httpd.conf "AllowEncodedSlashes On".
RewriteCond %{REQUEST_URI} ^(.*)\\(.*)$
RewriteRule .* %1/%2 [R=301,NC,L]
# Rewrite exceptions for specific path.
# RewriteRule ^images/ - [L]
# Rewrite space with dash.
RewriteCond %{REQUEST_URI} ^([^\ ]*)\ (.*)$
RewriteRule .* %1-%2 [R=301,L]
# Rewrite underscore with dash.
RewriteCond %{REQUEST_URI} ^([^\_]*)\_(.*)$
RewriteRule .* %1-%2 [R=301,L]
# Remove index.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php\ HTTP/ [NC]
RewriteRule .* http%{ENV:https}://%{HTTP_HOST}/%1 [R=301,L]
# Remove extension .php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*).php\ HTTP/ [NC]
RewriteRule .* http%{ENV:https}://%{HTTP_HOST}/%1 [R=301,L]
# Rewrite query string for AJAX crawling http://support.google.com/webmasters/bin/answer.py?hl=en&answer=174992
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*)$
RewriteRule .*$ %{REQUEST_URI}%1? [R=301,L]
# Remove question mark and parameters http://www.webmasterworld.com/apache/4341134-2-30.htm
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^?#\ ]*)\?[^\ ]*\ HTTP/ [NC]
# Query rewrite exceptions.
# RewriteCond $1 !^images/
# RewriteCond !{QUERY_STRING} callback
RewriteRule .*$ %{REQUEST_URI}? [R=301,L]
# Remove dot.
RewriteCond %{REQUEST_URI} ^([^\.]*)\.(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* %1%2 [R=301,L]
# Remove comma.
RewriteCond %{REQUEST_URI} ^([^\,]*)\,(.*)$
RewriteRule .* %1%2 [R=301,L]
# Remove dash before slash.
RewriteCond %{REQUEST_URI} ^(.*)\-/(.*)$
RewriteRule ^(.*)\-/(.*)$ %1/%2 [R=301,L]
# Remove dash at URL end.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)-\ HTTP/ [NC]
RewriteRule .* http%{ENV:https}://%{HTTP_HOST}/%1 [R=301,L]
# Rewrite uppercase letter URL to lowercase with httpd.conf "RewriteMap lc int:tolower"
# Solution without RewriteMap in https://github.com/laukstein/ajax-seo/wiki/Lowercase-URL
RewriteCond %{REQUEST_URI} .+
RewriteRule ^[^A-Z]*[A-Z] ${lc:%0} [R=301,L]
# Block access to folders that begins with a period, like directories of Subversion or Git.
RewriteRule "(^|/)\." - [F]
# URL rewrite.
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^api/?([^.]*)$ index.php?api&url=$1 [QSA,L]
RewriteRule ^([^.]*)$ index.php?url=$1 [QSA,L]
# Get the headers If-Modified-Since and If-None-Match when apache_request_headers() is not available.
RewriteRule .* - [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]
</IfModule>