Nginx Rewrite rules are acting up

I did a simple rewrite on a site I'm working on to essentially drop the .php from files, it's a little more verbose than I'd like but seems to work.

rewrite ^/(.*)$ http://site.com/$1 permanent;
rewrite ^/(.*)$ /$1.php;

This works fantastic but some of my scripting (mainly in oath) would prefer to allow the .php to pass through still, and now my images don't work no matter how they're linked.

Eventually I'll be needing to figure out how to write the rules to work for the wildcard DNS subdomain I stuff I have set up (as in user.site.com would be site.com/?uservar=user).

I'm fairly new to Nginx, luckily someone way smarter than myself in the arts of Nginx wrote a Wordpress port so my blog is working fantastic. Any help in this matter would be greatly appreciated. I tried my old working Apache rules in ~~[http://www.anilcetin.com/convert-apache-htaccess-to-nginx/" target="_blank">](http://www.anilcetin.com/convert-apache … -to-nginx/">http://www.anilcetin.com/convert-apache-htaccess-to-nginx/]( but they don't function in this sites config file.

1 Reply

I fixed it I with a little recon work via a few Nginx sites, seems that my initial logic was indeed flawed, below seems to work.

if (!-e $request_filename) {
rewrite ^/(.*)$ /$1.php;
}

Now hopefully when the time comes I can get the user.site.com rule working.

Reply

Please enter an answer
Tips:

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] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct