Apache Rewrite Rules & Resources
- Add Caching for Static Assets (Apache) - Add caching directives that browsers will use to cache static assets on the client side.
- Add/Remove Trailing Slash (Apache) - Add or remove the trailing slash in URLs to enforce consistent URL structure, good for SEO.
- Block Specific User-agents (Apache) - Block specific User-agents' requests. Useful for dealing with malicious bots.
- Canonicalize Host – Add/Remove www (Apache) - Canonicalize host names by either prepending www or explicitly omitting it from the domain name.
- Deny Request Based On Method (Apache) - Block requests when made with specific request methods.
- Dynamic robots.txt (Apache) - Rewrite requests for robots.txt to a dynamic file which generates robot directives.
- Enable GZip/DEFLATE Compression (Apache) - Enable compressed responses using GZip or Deflate to reduce bandwidth and increase performance.
- Enforce Lower Case URLs (Apache) - Force lowercase URLs, especially important for SEO on Windows-based servers, which are case-insensitive.
- Permanently Redirect Entire Directory (Apache) - Redirect an entire directory to another location. Useful when restructuring a website.
- Prevent Image Hotlinking (Apache) - Stop other sites from using your images as their own.
- Redirect All HTTP Requests To HTTPS (Apache) - Redirect all non-secure (HTTP) requests to use a secure (HTTPS) connection.
- Redirect Default Document to Directory (Apache) - Redirect all requests to default documents to their parent directory URL. Important SEO tactic to avoid duplicate content penalties.
- Remove File Extensions From URLs (Apache) - Simplify URLs slightly by removing file extensions. Used to tidy up URLs a bit, not to 'cloak the technology in use'.
- Reverse Proxy To Another Server (Apache) - Proxy an intranet, or other, server's content through a different webserver.
- Rewrite URL as Query String Parameters (Apache) - Convert URL structure to query string parameters. Use to create SEO friendly URLs.
- Serve Images from New Directory (Apache) - Serve images from a new directory, whether by rewrite or redirect.
- Whitelist/Blacklist IP Addresses (Apache) - Allow or deny requests based upon the requesting IP address. Useful when a site is under maintenance or to block repeat offenders.
Articles & Resources
- Apache VHost File vs .htaccessApache rewrite rules can be configured in either virtual host configuration files or in .htaccess. Which is best?
- .htaccess Rule TesterTool which tests your rewrite rules against a URL you enter.
- .htaccess Syntax CheckTool which finds syntax errors in .htaccess files so you can avoid breaking your site unnecessarily.
- Apache 2.4 Security TipsTips on security issues for Apache and other web servers.
- Apache mod_rewrite Reference DocumentationThe official Apache documentation for the mod_rewrite module.
- List of all Apache rewrite flagsFull list of all available flags for the Apache mod_rewrite module.
- Regular Expressions Intro to mod_rewriteIntroduction to using regular expressions with the mod_rewrite module.
- Using a RewriteMap for Specialized RewritesDocument which covers the use of RewriteMap to perform rewriting that is too complicated or too specialized for regular expressions.
The Apache HTTP Server Project is a secure, highly customizable, and extensible web server which has an unrestricted license and is under continuous development. The majority of Apache HTTP Server instances run on Linux but current versions also run on Windows and a variety of Unix-like systems. It is currently the most popular web server on the Internet with about 45% market share.