I am struggling to understand how to edit my .htaccess file.
Currently i have the following url example.com/fixture.php?country=UK&cup=prem&year=1998&id=123
I would like to achieve example.com/UK/prem/1998/123
On each of the parameters in the URL will have a page for example example.com/UK/prem/ will have info regarding the league and other cups same as the country parameter will have info on the page too.
Currently here is my .htaccess file
RewriteEngine On
RewriteRule ^fixture\.php$ - [L]
RewriteRule ^([^/]+)/?$ /fixture.php?id=$1 [L,QSA]
RewriteRule ^([a-z]{2})/([^/]+)/?$ /fixture.php?country=$1&cup=$2 [L,QSA]
RewriteRule ^([^/]+)/([0-9]+)/?$ /fixture.php?country=$1&cup=$2year=$3&id=$4 [L,QSA]
Currently I only get a 404 status. I have searched stack overflow and adapted the above code, this is where I think I run into issues....
With your shown samples, please try following rules set in htaccess file. Please make sure your htaccess file is present in root folder/directory.
Also make sure to clear your browser cache before testing your URLs.
RewriteEngine On
##Blocking direct access to fixture.php here, added NC flag here.
RewriteRule ^fixture\.php$ - [NC,L]
##Rules for handling 4 parameters in uri.
RewriteRule ^([^/]*)/([^/]*)/(\d{4})/\d{3}/?$ /fixture.php?country=$1&cup=$2year=$3&id=$4 [L,QSA]
##Rules for handling 2 parameters in uri.
RewriteRule ^([a-zA-Z]{2})/([^/]+)/?$ /fixture.php?country=$1&cup=$2 [L,QSA]
##Rules for handling 1 parameter in uri.
RewriteRule ^([^/]*)/?$ /fixture.php?id=$1 [L,QSA]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With