Symptom?
Solution quickly
if (!-e $request_filename) {
rewrite ^/wordpress/(.+)$ /wordpress/index.php?p=$1 last;
}
Detailed explanation
The URL or address is composed of the hostname and pathname/filename in the form of http://hostname/pathname/filename (I knowingly simplify a bit)
What the first line does is, only execute the rest if the filename is not found (which is normal as the friendly URL does not match a file on the drive).
The second line is a regular expression which basically pass the filename to WordPress index.php (which exists physically on the drive) to return the desired page.
Regular expression for dummies
- ^ = start to match from the start of the line. Here, the start of the line is after the hostname. In our example: /2010/07/nginx-rewrite-rule-for-wordpress-buddypress/247
- /wordpress/ = scan to find that text in the line
- (.+) = scan to match anything and keep it as a search result
- $ = and do that until the end of the line.
- $1 = the result of the matched text/pattern, in our case 2010/07/nginx-rewrite-rule-for-wordpress-buddypress/247
Rewrite for dummies
The command is read from left to right and is telling the server: if you see that, do that instead.
In our example with the regular expression, it means pass what was matched to index.
This means that when you type http://k-noo.net/2010/07/nginx-rewrite-rule-for-wordpress-buddypress/247, what is actually being called is http://k-noo.net/index.php?p=2010/07/nginx-rewrite-rule-for-wordpress-buddypress/247
Note that because the leading “/” is in the text to match (i.e. /(.+)$ ), it is not passed to the index.php (i.e. it is not part of $1)
Yeah but…
The other simplification I did is that, with nginx, you will have almost pretty permalinks…. and not pretty permalinks
Please, do feel welcome to comment to highlight a mistake I did or if it has been useful to you.
Cheers, Alban
Reference
- Nginx rewrite rules with wpmu, wp super cache, bbpress and sitemaps support – This is a more complex integration
- WordPress permalinks – The different types available
- WordPress friendly URLs – Which type of permalinks to use
Comments
Leave a comment Trackback