Nginx Rewrite rule

Hi all

I have the following rewrite working perfectly on an Apache based server:

RewriteRule my-special-WP-category/(.*)$ ?my-ugly-variable=$1

However no matter what variation of the following I put in /usr/local/nginx/sites-available/ on my Nginx Server I get no redirect :shock:

if (!-e $request_filename) {
 rewrite  my-special-WP-category/(.*)$  ?my-ugly-variable=$1  last;

By placing the rewrite code before the include /usr/local/nginx/conf/wordpressparams.supercache; line I get a 500 Internal Server Error and in the logs this: "the rewritten URI has a zero length"

The only other thing I have seen in the sites' logs is the following error which makes me think that Nginx is looking for a real directory instead of the WP virtual one with one of my desperate varations!

"/home/public_html/" is not found

Many thanks for ANY help with this :)

2 Replies

i might suggest using the full URI path's in your rewrite in nginx.

So something like

if (!-e $request_filename) {

rewrite my-special-WP-category/(.*)$ /index.php?my-ugly-variable=$1 last;



Or what ever script you are executing in the redirect.


Sory man, thanks so much for this that simple piece of code has FINALLY sorted this.

Thank again and apologies for the first over the top reply :lol:


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct