301 redirection with .php in url


#1

I have a WordPress site and I"m trying to have custom 301 redirects. I’m trying to implement this either via a plugin or written in a location block.

Non .php urls work eg: http://wordpresssite.org/old can be 301’d to http://wordpresssite.org/new either via that plugin or

location = /old { return 301 /new ;}

However URL’s with “.php” fail to properly be redirected.

From what I can infer my trouble stems from how wpfc.conf is set up. There is a location block that reads:

location ~ \.php$ { try_files $uri =404; fastcgi_pass php; }

Example: http://wordpresssite.org/index.php?whaev=whatev will produce a WordPress 404 cause index.php is valid and PHP can parse it.

However: http://wordpresssite.org/podcast/pod.php?show=yayashow will throw a nginx 404 because /podcast/pod.php doesn’t exist and PHP can’t deal with it (it will not throw a PHP 404 because of =404 in try_files I presume).

So my question is: What config changes do I need to make to allow Nginx to properly redirect missing .php url requests and throw a 301 to where I specify.

Example of what I’m trying to accomplish:

http://wordpresssite.org/podcast/pod.php?show=yayashow 301’d to http://wordpresssite.org/program/yay-a-show/feed/

Thanks!


.php to non php redirect
#2

You can try something like:

location = /podcast/pod.php {
   return 301 http://wordpresssite.org/program/$arg_show/feed/ ;
}

location = /something.php will be executed first so that particular request won’t reach location ~ \.php$ block.


#3

Hi @Brian_D

It’s been a long time, and we haven’t heard from you. It looks like your issue is resolved.

I am closing this support topic for now. Feel free to create a new support topic if you have any queries further. :slight_smile:


#4