Welcome! Log In Create A New Profile

Advanced

Converting Apache RewriteRule to Nginx regex

Posted by jamesdkirk 
Converting Apache RewriteRule to Nginx regex
July 01, 2009 08:17PM
[b]Hey Jim! Back again[/b]

Have been plodding around trying to use a [url=http://premium.wpmudev.org/project/sitemaps-and-seo-wordpress-mu-style]sitemap generator plugin[/url] on my WordPress MU install. I've got the files placed according to the plugin's directions, and there's an added instruction that the following RewriteRule be placed into the .htaccess file:
[code]
RewriteRule ^(.*/)?sitemap.xml wp-content/sitemap.php [L]
[/code]

I've attempted to "translate" this Apache regex code as follows:
[code]
#attempting to translate the sitemaps.xml rewrite
rewrite ^(.*)?sitemap.xml wp-content/sitemap.php break;
[/code]

And have it placed in my virtual host file, as such:
[code]
server {
server_name domain-name.tld
location / {
root /path/to/root/directory/;
index index.php;

rewrite ^(.*)?sitemap.xml wp-content/sitemap.php break;
}
}
[/code]

Without the rewrite code, I get the 404 within the WordPress install (meaning WP will direct the browser to show the theme 404 page.) With the above code, I get the browser default 404 page (varies with browser type. Google Chrome, for instance shows me a convenient search Google box.)

What to do?! Looking to find the correct rewrite directive as well as the proper place to insert it.

I'm sure you can help, Jim. You're clearly the Nginx MASTER (shameless flattery!)

Thanks.

~~~~~~~~~~
James D Kirk
jamesdkirk.com
Re: Converting Apache RewriteRule to Nginx regex
July 01, 2009 08:50PM
Try
[code]
rewrite ^/(.*)?sitemap.xml /wp-content/sitemap.php break;
[/code]

or

[code]
rewrite ^/(.*)?sitemap.xml /wp-content/sitemap.php last;
[/code]

Both may work but I suspect the latter one is more likely to do so.

--
Jim Ohlstein
Re: Converting Apache RewriteRule to Nginx regex
July 01, 2009 09:14PM
Hey, thanks Jim.

That "last" seems to work. Now I just have to find out if the output that is generated on my [url=http://inverdevalley.com/sitemap.xml]sitemap.xml[/url] page is correct, but that's not an Nginx, go to Jim question!

Thanks again. I'll be back!

~~~~~~~~~~
James D Kirk
jamesdkirk.com
Re: Converting Apache RewriteRule to Nginx regex
July 01, 2009 11:25PM
My pleasure. :)

--
Jim Ohlstein
Re: Converting Apache RewriteRule to Nginx regex
July 04, 2009 12:36AM
Thought I'd be able to stay away longer, Jim!

Also thought I'd be able to apply what I learned from my last request to this one:
[code]
RewriteRule ^(.*/)?avatar/(.*) wp-content/avatar.php?file=$2 [L]
[/code]

by going with:
[code]
rewrite ^/(.*/)?avatar/(.*) wp-content/avatar.php?file=$2 last;
[/code]

But alas, no go!

Trust you're having a great weekend. TIA!

~~~~~~~~~~
James D Kirk
jamesdkirk.com
Re: Converting Apache RewriteRule to Nginx regex
July 04, 2009 06:40PM
You're missing a leading forward slash:

[code]
rewrite ^/(.*/)?avatar/(.*) /wp-content/avatar.php?file=$2 last
[/code]

Happy Fourth!

--
Jim Ohlstein
Re: Converting Apache RewriteRule to Nginx regex
July 05, 2009 03:39PM
Cool. Will give it a try and report back.

Thanks!

~~~~~~~~~~
James D Kirk
jamesdkirk.com
Re: Converting Apache RewriteRule to Nginx regex
July 05, 2009 05:35PM
Hey Jim,

You inclusion of the leading forward slash did the trick, sort of!

This might be a good reference for duffers like me that bite off more than they can chew. That translation of the Apache RewriteRule from the Premium WordPress MU plugin, Avatars 3.3.3 needs to be inserted prior to any code that stops after processing the Nginx serving of static files.

I had placed the correct code just after the static file serving code, and the Avatar was not showing. Then it finally slapped me in the face that the server was moving on from static file processing.

Simply moving the rewrite above the other static file serving did the trick!

Thanks again for your guidance. I'll be back (putting a wager on it!)

~~~~~~~~~~
James D Kirk
jamesdkirk.com
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 71
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready