Generated by GPT-5-mini| mod_rewrite | |
|---|---|
| Name | mod_rewrite |
| Author | Apache HTTP Server Project |
| Developer | Apache Software Foundation |
| Released | 1997 |
| Operating system | Cross-platform |
| License | Apache License 2.0 |
mod_rewrite mod_rewrite is a URL rewriting module for the Apache HTTP Server that provides a powerful and flexible way to manipulate request URLs. It operates as an engine to transform incoming URI strings using pattern matching, conditional rules, and substitution, and is commonly used in web applications, content management systems, and reverse proxy setups. Administrators and developers integrate mod_rewrite with server configuration, virtual hosts, and content routing to implement redirects, canonicalization, and friendly URL schemes.
mod_rewrite was introduced as part of the Apache HTTP Server ecosystem and evolved alongside projects such as Apache HTTP Server, Apache Software Foundation, OpenSSL, OpenBSD, and FreeBSD. The module interacts with components like VirtualHost (Apache), HTTP/1.1, HTTP/2, and operating systems including Linux, Windows NT, macOS, and Solaris (operating system). It is often deployed together with software stacks such as LAMP, LEMP, WAMP, and alongside web servers like Nginx, Microsoft Internet Information Services, and Lighttpd. Administrators commonly reference standards and organizations including the IETF, W3C, Internet Engineering Task Force, and protocols like URI and Uniform Resource Identifier when designing rewriting strategies.
mod_rewrite offers features such as pattern matching using regular expressions, back-references, conditionals, and flag-driven behaviors similar to tools found in projects like Perl, PCRE, GNU grep, and sed (Unix). It supports environment variable manipulation compatible with POSIX, integration with authentication modules such as mod_auth_basic, mod_auth_digest, and logging interoperability with syslog, rsyslog, Log4j, and ELK Stack. mod_rewrite can perform external redirects, internal rewrites, proxying to backends like FastCGI, SCGI, WSGI, and integration with platforms such as WordPress, Drupal, Joomla!, Magento, MediaWiki, and TYPO3. Support for conditional expressions allows interaction with services like Memcached, Redis, MySQL, PostgreSQL, and caching systems including Varnish and Squid.
Configuration is generally performed in server-level configuration files used by Apache HTTP Server such as httpd.conf or in directory-level files like .htaccess within environments like GitHub Actions or orchestration systems such as Docker and Kubernetes. Rule syntax uses directives such as RewriteEngine, RewriteRule, RewriteCond, and flags (L, R, NC, QSA, NE) with regular expressions anchored by PCRE syntax from Perl Compatible Regular Expressions. Administrators often consult resources produced by organizations and figures like Tim Berners-Lee, Brian Behlendorf, Guido van Rossum, Linus Torvalds, and Richard Stallman for standards and licensing context. Integration examples appear in deployments with NGINX, Apache Tomcat, Jetty, and platforms like Heroku, Amazon Web Services, Microsoft Azure, Google Cloud Platform, and DigitalOcean.
Typical use cases include creating search-engine-friendly URLs for WordPress, redirecting deprecated endpoints in Drupal, URL canonicalization for Magento, masking backend architecture such as Node.js or Django (web framework), and implementing language negotiation for sites like BBC or The New York Times. Examples include redirects for moved resources referenced in media like Wikipedia, rewriting for single-page applications deployed via React (JavaScript library), AngularJS, or Vue.js (framework), and proxying API endpoints back to services like Stripe (company), PayPal, GitLab, or Jenkins. Administrators combine mod_rewrite with security measures used by Cloudflare, rate-limiting proxies such as HAProxy, and content delivery networks like Akamai and CloudFront.
Performance tuning often considers alternatives like offloading to Nginx, using native application routing in Express.js, or leveraging proxy caching in Varnish. Security best practices recommend avoiding untrusted user input in regular expressions to mitigate risks similar to ReDoS vulnerabilities discussed in advisories by organizations like CERT, US-CERT, and OWASP. Administrators apply principles established by entities such as National Institute of Standards and Technology, European Union Agency for Cybersecurity, and ENISA when hardening servers with modules like mod_security and TLS provided by OpenSSL or BoringSSL. For maintainability, teams use version control systems like Git, continuous integration with Travis CI or GitHub Actions, and configuration management via Ansible, Puppet, or Chef.
Alternatives to mod_rewrite include built-in routing in application frameworks such as Ruby on Rails, Django (web framework), Express.js, ASP.NET Core, and reverse proxies like Nginx, HAProxy, Traefik, and Caddy (web server). Static site generators such as Jekyll, Hugo (software), Gatsby (JS framework), and Next.js reduce reliance on server-side rewriting by generating prebuilt routes. Comparisons often weigh factors popularized by projects and companies like Google, Facebook, Amazon, Netflix, and GitHub regarding scalability, maintainability, and security. Many organizations choose architecture patterns promoted by 12factor or practices from DevOps thought leaders such as Jez Humble and Gene Kim to decide whether to centralize rewriting in web servers or handle routing in application layers.