last day (15 days later) » 

10:41 PM
0
Q: apache to nginx rewrite issues

Ryan KnoppI'm trying to convert RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php RewriteRule (.*)\.php$ /$1/ [L,R=301] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*)/$ $1.php [L] RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule (.*[^/])$ /$1/ [L,R=301] in to a...

 
I could help but please explain to me the logic of the first rewrite.
 
@MohammadAbuShady The first is taking anything with *.php and making it into a directory call. So for instance domain.com/faq.php would then rewrite to domain.com/faq/
 
I just noticed you said the downloading part, this means your code works but there's a problem with the location ~ \.php$, check the php settings, could be a wrong sock file or you should to be using a port, please paste me the line that begins with listen inside /etc/php5/fpm/pool.d/www.conf
 
@MohammadAbuShady It's listen = /var/run/php5-fpm.sock. If I just go to the host.com/ it renders right. It's just the redirect that doesn't render. It's like it's not sending the file back threw the "location ~ \.php" block.
 
try adding the rule directly to the try_files, try_files $uri $uri/ $uri.php
 
10:41 PM
Thanks @MohammadAbuShady, That works great for "host.com/page" but how about "host.com/page/" with the leading slash.
 
try adding this in the server scope above the location rewrite ^/(.*)/$ /$1 permanent;
 
@MohammadAbuShady That works but it's backwards. I want /page to redirect to /page/. Then /page/ be rendered by page.php. currently /page renders to page.php and /page/ redirects /page. Thanks so much for your help.
 
This would be a little bit tricky, because then nginx would look for "page/.php", which would show a 404
 
Is there anyway to take out the leading slash before processing the php files? Be like /page/ => /page => /page.php of course leaving the /page/ in the url bar.
 
yea well i guess we'll have to return the @extentionless part again
Try this instead: ( after you return your old try_files )
location @extensionless-php {
rewrite ^(.*)/?$ $1.php last;
}
actually make it $1\.php , more specific, so
rewrite ^(.*)/?$ $1\.php last;
@RyanKnopp ping
 
11:24 PM
Returns with "No input file specified.". I'm guessing the php file isn't getting pass into the fpm.
@MohammadAbuShady
 
11:44 PM
try adding this to your php block
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
@RyanKnopp
 

  last day (15 days later) »