background preloader

Mod_rewrite

Facebook Twitter

Apache2 - Apache 2.4.x ip blacklist. Htaccess to nginx converter. URL Rewriting for the Fearful. I think it was Marilyn Monroe who said, “If you can’t handle me at my worst, please just fix these rewrite rules, I’m getting an internal server error.” Even the blonde bombshell hated configuring URL rewrites on her website, and I think most of us know where she was coming from. The majority of website projects I work on require some amount of URL rewriting, and I find it mildly enjoyable — I quite like a good rewrite rule. I suspect you may not share my glee, so in this article we’re going to go back to basics to try to make the whole rigmarole more understandable. When we think about URL rewriting, usually that means adding some rules to an .htaccess file for an Apache web server. As that’s the most common case, that’s what I’ll be sticking to here. If you work with a different server, there’s often documentation specifically for translating from Apache’s mod_rewrite rules.

This isn’t going to be a comprehensive guide to every URL rewriting problem you might ever have. The basics [a-z] Rewrite. Redirecting and Remapping with mod_rewrite. Available Languages: en | fr This document supplements the mod_rewritereference documentation. It describes how you can use mod_rewrite to redirect and remap request. This includes many examples of common uses of mod_rewrite, including detailed descriptions of how each works. Note that many of these examples won't work unchanged in your particular server configuration, so it's important that you understand them, rather than merely cutting and pasting the examples into your configuration. From Old to New (internal) Description: Assume we have recently renamed the page foo.html to bar.html and now want to provide the old URL for backward compatibility. Solution: We rewrite the old URL to the new one internally via the following rule: RewriteEngine on RewriteRule ^/foo\.html$ /bar.html [PT] Rewriting From Old to New (external) Assume again that we have recently renamed the page foo.html to bar.html and now want to provide the old URL for backward compatibility.

Discussion From Static to Dynamic.