Understanding Pseudo-Static (URL Rewriting) and Its Implementation in Apache and Nginx
This article explains what pseudo‑static (URL rewriting) is, compares its advantages and disadvantages with true static pages, and provides detailed implementation methods and example rewrite rules for both Apache and Nginx servers to improve SEO, reduce server load, and simplify URL structures.
Pseudo‑static, also known as URL rewriting, transforms dynamic URLs (e.g., *.php, *.asp) into static‑looking URLs (e.g., *.html) to improve SEO and provide cleaner links, while the underlying page remains dynamic and still accesses the database.
Compared with true static pages, pseudo‑static reduces the need for manual file generation and saves disk space, but it can increase CPU usage because each request still triggers regex matching and database queries; true static pages are faster but harder to maintain.
Implementation on Apache requires enabling the rewrite module ( LoadModule rewrite_module modules/mod_rewrite.so ) and allowing .htaccess files ( AllowOverride All ). On Nginx, rewrite support is built‑in.
Two common configuration approaches are: (1) adding rewrite rules directly in the virtual‑host configuration, and (2) placing them in a .htaccess file (Apache) or a separate include file (Nginx).
Typical rewrite examples include:
RewriteEngine on
RewriteRule (.*)\.php$ http://b.example.com/$1.jsp [R=301,L,NC]
location / { rewrite c(\d+)_(.*)\.html /index.php?c=user&m=index&id=$1&title=$2 last; }
location ~* \.(gif|jpg|png)$ { valid_referers none blocked http://example.com; if ($invalid_referer) { rewrite ^/ http://example.com/blocked.html; } }Common regex symbols used in rewrite rules are explained (e.g., ~ , ~* , \d , \w , ^ , $ ) along with flags such as last , break , redirect , and permanent .
Typical use cases include normalising URLs for better user experience, redirecting after domain changes, and conditional redirects based on variables, client information, or request patterns.
Overall, the article provides a comprehensive guide to using pseudo‑static rewrite rules to optimise website performance, SEO, and URL aesthetics on both Apache and Nginx platforms.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.