I have wordpress installed in the root directory of the domain.
I am using pretty links and fast cgi caching.
Now I have a directory inside the root directory (e.G. "/course/") that contains some .php files that have nothing to do with wordpress. I would love to access these files without the .php extension.
On another server where everything is setup inside the root directory and I don't use wordpress its working with these additions to the server block:
location / {
try_files $uri $uri.html $uri/ @extensionless-php;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
I am struggeling to get it working on my wordpress server. Maybe I am missing something, here is the complete server block:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.php index.html index.htm;
client_max_body_size 10M;
server_name example.com www.example.com;
location ~* "^/something" {
rewrite ^ http://example.com/curso-gratis-habitos/$ $1?ref=conlasalud permanent;
}
location ~* "^/some-other-thing" {
rewrite ^ https://someotherurl.com/? permanent;
}
location ~* "^/something-else" {
rewrite ^ https://someotherurl.com/? permanent;
}
location ~* "^/another-one" {
return 301 https://someotherurl.com/;
}
location ~* "^/special-url" {
return 301 https://someotherurl.com/;
}
set $cache_uri $request_uri;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $cache_uri 'null cache';
}
if ($query_string != "") {
set $cache_uri 'null cache';
}
# Don't cache uris containing the following segments
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-$
set $cache_uri 'null cache';
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
set $cache_uri 'null cache';
}
location ~ \.php$ {
try_files $uri @extensionless-php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# Use cached or actual file if they exists, otherwise pass request to WordPress
location / {
try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php @extensionless-php;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
}
server { root /var/www/html/course; index index.php index.html index.htm; location / { try_files $uri $uri/ $uri.php $uri.html; } }