nystudio107 / nginx-craft

An Nginx virtual host configuration for Craft CMS that implements a number of best-practices.
MIT License
310 stars 37 forks source link

Difficulty redirecting .php files #8

Closed iparr closed 7 years ago

iparr commented 7 years ago

I'm migrating from an old site with a lot of .php links littered across the domain.

I want to redirect all of these to the URLs without the .php extension.

I'm trying to use the Retour plugin to help me do this, but I've also tried modifying this config.

I just get "File not found." Help!

This is very helpful, otherwise!

khalwat commented 7 years ago

Outside of scope

iparr commented 7 years ago

Have found a fix for items within a folder. Will share in case someone else is looking for a solution to what I'd imagine is a reasonably likely scenario:

location ~ /learn/.*\.php$ {
    try_files $uri $uri/ /index.php?$query_string;
}

Then use Retour to set up a RegEx redirect:

/learn/(.+?)(\.[^.]*$|$) -> /learn/$1

Where learn is the name of the folder. Not bold enough to do this everywhere.

iparr commented 7 years ago

Although this commit is a much cleaner solution: https://github.com/nystudio107/nginx-craft/commit/65ad2868876c436f90ec80f0eee20fe9e3429607