Question on rewriting ...

Igor Sysoev is at rambler-co.ru
Tue Sep 4 22:59:33 MSD 2007


On Mon, Sep 03, 2007 at 11:51:25AM +0400, Rakhesh Sasidharan wrote:

> I have http://domain/. Nginx is installed as my webserver, WordPress as 
> the blog at /net/store/www/data/wordpress, and here's the relevant bits 
> from my config file:
> 
> ------8<-----------------------
> location / {
>      root        /net/store/www/data/wordpress;
>      index       index.php;
> 
>      if (!-e $request_filename) {
>          rewrite ^(.*)$  /index.php?q=$1 last;
>      }
> }
> ------8<-----------------------
> 
> This config works as expected. I can access my blog at http://domain/, the 
> feeds at http://domain/feed/ and so on ... a typical WordPress blog.
> 
> Now, for not much reason apart from the fact that I want to play around 
> (and learn things), I am trying to setup a rewrite rule such that any 
> hits to http://domain/feed/<whatever> (an incorrect URL for feeds) get the 
> <whatever> bit stripped out and rewritten to http://domain/feed/.
> 
> So I modify the config to the following:
> 
> ------8<-----------------------
> location / {
>      root        /net/store/www/data/wordpress;
>      index       index.php;
> 
>      if (!-e $request_filename) {
>         rewrite ^/log/(.*)?$                    /index.php?q=$1 last;
> 	rewrite ^/feed/(rss|rss2|atom|rdf)$     /?feed=$1       last;
>         rewrite ^/feed/.+$                      /index.php      last;
>      }
> }
> ------8<-----------------------
> 
> All my posts are under the /log location (that's part of the permalink 
> structure I setup in WordPress). So my idea is to
>  * rewrite all hits to http://domain/log to the posts,
>  * rewrite all hits to http://domain/feed/(rss|rss2|atom|rdf) to the 
> correct feeds, and
>  * rewrite all hits to http://domain/feed/<whatever> to 
> http://domain/index.php.
> 
> The first two work as required.
> 
> The third one seems to work sort of coz I get my blog page, but with a 404 
> error message from WordPress! So that leads me to think the URL is not 
> getting rewritten the way I want -- it is getting rewritten but for some 
> reason the "/feed/<whatever>" bit too is passed on to index.php. And this 
> is the cause for the 404 error.
> 
> Any ideas why this is happening the way it is? Strangely enough, when I 
> modify the /feed/<whatever> rule to redirect to http://rakhesh.com/ 
> instead of just rewrite, things work! So I figure I've got something wrong 
> in my understanding of these rewrite rules ...

Try set
error_log   /path/to/log  notice;

     location / {
          rewrite_log  on;
          ...


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list