0

I'm working on a client site in which I need to receive parameters, passed in the URL, and process them to get data on another page. For example, I have a dropdown list of Football Teams on a page. When the user selects a team, they are redirected to a Teams page, e.g. /football/chelsea-fc/

This is a Wordpress site, so that URL results in a 404 error, unless I set up a specific page for that site. Since there could be hundreds of teams, I don't want to do that. Instead, I've set up one page, with its own PHP template called 'Football'. Its slug is /football/ (template-football.php)

I need to send the /chelsea-fc/ portion of the URL to template-football.php as aparameter, so I can process it and get the data related to that team. But Wordpress removes the paramter from the URL.

I'm imagined the solution involved one or more .htaccess rules, but at the moment I'm failing to pass through the parameters. Here's what I've got so far: RewriteRule ^football/^([A-Za-z0-9]+)/$ /template-football.php=$1 [QSA,L]

Can anyone point me in the right direction with this please?

Thanks in advance!

  • Rewriting to the template file directly is of course absolutely wrong to begin with - the template file _alone_ does not provide the full page you are interested in, it needs to be called _within_ the WP context. You rather need to add your own rewrite within WP itself, something like https://stackoverflow.com/a/45385599 – CBroe May 20 '20 at 10:49
  • Thanks @CBroe I've read through that link and it makes sense, however I still can't get it to rewrite the URL. If the URL is www.example.com?football=team123, it merely becomes www.example.com/?football=team123 NOT www.example.com/football/team123 Have you any idea what I may be doing wrong? I also have this in the .htaccess file: RewriteRule ^football/^([A-Za-z0-9]+)/$ /football=$1 [QSA,L] Any further ideas, please? Thanks in advance. – willothewisp May 22 '20 at 10:04

0 Answers0