Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect .php extension to WordPress if not exists #204

Open
jessuppi opened this issue Sep 3, 2023 · 4 comments
Open

Redirect .php extension to WordPress if not exists #204

jessuppi opened this issue Sep 3, 2023 · 4 comments

Comments

@jessuppi
Copy link
Member

jessuppi commented Sep 3, 2023

We should consider doing this, in case of websites that have a history of using various CMS and such, to avoid tons of 404 errors which are bad for SEO and usability.

Some reading:

https://stackoverflow.com/questions/38911354/nginx-php-file-extension-does-not-work-with-try-files

Side note, we should also organize our server blocks better per answers here.

@jessuppi
Copy link
Member Author

I had thought this wasn't working correctly, but seems that it is working fine actually:

location ~* \.php$ {
    include /etc/nginx/fastcgi.conf;
    try_files $uri $uri/ /index.php?$args; ## send .php requests to WordPress if not found
...
}

Ref: https://serverfault.com/questions/901761/nginx-redirect-to-a-php-file-with-try-files-if-required-php-file-not-found

Ref: https://github.com/littlebizzy/slickstack/blob/master/modules/nginx/sites/production.txt

So I'm closing this for now.

@jessuppi jessuppi reopened this Nov 12, 2023
@jessuppi
Copy link
Member Author

It's still not working consistently. I discovered it's a conflict with FastCGI Cache rules, this snippet:

## blank session and strip cookie header if cached page ##
if ($skip_cache = 0 ) {
        set $ss_session "";
        more_clear_headers "Set-Cookie*";
}

...under the location ~* \.php$ { block. Disabling FastCGI Cache on a SlickStack server fixes it immediately...

@jessuppi
Copy link
Member Author

I see GridPane skips FastCGI cache on .php files:

https://gridpane.com/kb/gridpane-default-cache-exclusions/

Thus, their similar redirect of non-existent .php files probably works more consistently:

https://gridpane.com/kb/redirects-with-non-existent-php-files/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant