apache server sides includes and htaccess notes
TRANSCRIPT
-
8/3/2019 Apache Server Sides Includes and Htaccess Notes
1/3
Apache Server Sides Includes and .htaccess
Notes
1. How to get rid of referral spam with the .htaccess file.
Place the following in your top level .htaccess file and all requests from urls containing the
terms in the list will be sent to your 403 page.
RewriteEngine OnRewriteBase /SetEnvIfNoCase Referer ".*(lenarcic|casino|more-poker|medportal).*"BadReferrerorder deny,allowdeny from env=BadReferrer
2. Redirect all of one extension to another extension
All requests to file1.txt are redirected to file1.shtml.
RewriteEngine OnRewriteBase /myDirectoryRewriteRule ^(.*).txt$ $1.shtml [R=301]
3. Redirects with spaces
I had an external web site link to one of my pages, but a space was accidentally appended
to the link, eg., "Pennies". My
error.log file was filling up with 404 errors. The easy solution was to do an apache
redirect, but it was a little tricky because of the space. I tried putting in the "%20" at the
end, but apache liked simple double quotes to define the trailing space.
Redirect "/Misc/Pennies/ " http://www.fincher.org/Misc/Pennies
4. Direct proxies to cache images
Put this code in ".htaccess"
### activate mod_expiresExpiresActive On
### Expire .gif's 1 month from when they're accessed#ExpiresByType text/html "access plus 30 days"ExpiresByType image/gif "access plus 30 days"ExpiresByType image/jpg "access plus 30 days"ExpiresByType image/jpeg "access plus 30 days"
5. How to define a custom error page
Put this code in ".htaccess"
ErrorDocument 403 /errors/403.htmlErrorDocument 404 /errors/404.html
6. Simple include:
-
8/3/2019 Apache Server Sides Includes and Htaccess Notes
2/3
-
8/3/2019 Apache Server Sides Includes and Htaccess Notes
3/3
In the directory to protect create a file named ".htaccess". Example of a directory named
"vacation":
AuthName "vacation"AuthType BasicAuthUserFile /big/dom/xsmith/.htpasswd
require user family
15. Example of conditionals16. 17.18. 19. Changes in the system are hard to implement20. Risk management is difficult21. Projects must be well defined at the beginning22. Cost of fixing errors in requirements increases by 10X at each
stage23. 24. ___________________________________
25. ___________________________________26. ___________________________________27. ___________________________________28.29.
30. Using predefined variables.31. This document is located at www.fincher.org
which will produce:
This document is located at www.fincher.org/tips/web/apache.shtml
32. Getting the QUERY_STRING from the url:33.
34. "echo" options
By default, echo will encode things like "". To prevent encoding of the variable
use the "encode='none'" attribute.
...The following is probably in a different file...
This document is located at www.fincher.org/tips/web/apache.shtml