How can I redirect old .php pages to new HTML pages on my WordPress site?

0
9
Asked By CreativeFalcon17 On

I recently revamped a business website, but all of the old pages had URLs ending with a .php format, like /services.php?section=121212. Now that I've migrated to a WordPress site, I'm struggling to get these old .php links to properly redirect to their new HTML counterparts. I'm using a 301 redirection plugin, but none of the old .php pages are redirecting and instead throw a 404 Not Found nginx error. I suspect the server is directly handling .php requests, so the redirection isn't working, even with a 404 plugin intended to redirect those pages to the homepage. Any advice on how to resolve this issue? I feel like I might be overlooking something basic.

4 Answers

Answered By TechGuru88 On

It sounds like the way your server is set up could be the issue, especially if you’re using nginx. Since nginx ignores .htaccess files, your redirects set in there aren't being executed. I'd recommend setting up the 301 redirects directly in your nginx server block configuration instead. You may want to look for the section in your nginx config (usually found in /etc/nginx/sites-available/), where you can map the old URLs to the new pages.

Answered By WebmasterJoe On

If you are using cPanel or Plesk, there are server-level redirect options you can easily implement. If it’s a self-hosted project, add 301 redirects in your site’s config files directly. This should help bypass the issues with handling .php requests.

Answered By DevDude42 On

You're correct about needing to work in the nginx configuration. Rather than relying on redirection plugins, which may not have the chance to run, you'll likely need to implement something similar to this in your config:

map $request_uri $redirect_target {
"~^/services.php?section=121212$" /new-page-one;
"~^/services.php?section=343434$" /new-page-two;
}
server {
...
if ($redirect_target) {
return 301 $redirect_target;
}
...
}

This way, you're actively telling the server to redirect these requests.

Answered By CodeWiz123 On

Make sure to handle the redirects from the server level since WordPress might not be reaching those old .php pages at all due to the server returning a 404. You may need a silent URL rewrite or a proper browser redirect based on your setup. It’s definitely something you’ll manage in the nginx config, not through .htaccess files.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.