Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

SEO friendly links PHP / htaccess problem

  • 26-04-2015 01:47PM
    #1
    Registered Users, Registered Users 2 Posts: 156 ✭✭


    I am trying to set up SEO frendly links for a PHP application. I think I am close but I am caught with an issue.

    Here is the original url -

    http://localhost/web/test/index.php?p1=ireland

    By adding the following to my .htaccess -

    [HTML]RewriteRule ^index.php/([0-9a-zA-Z_-]+) index.php?p1=$1 [NC,L][/HTML]

    this SEO friendly URL leads me to the same page -
    http://localhost/web/test/index.php/ireland

    If I am passing in 2 parameters like so -
    http://localhost/web/test/index.php?p1=ireland&p2=cork

    The following .htaccess entry does the trick -
    [HTML]RewriteRule ^index.php/([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+) index.php?p1=$1&p2=$2 [NC,L][/HTML]

    Now I can use -
    http://localhost/web/test/index.php/ireland/cork

    The problem is I seem to be able to use only one of these rules in my .htaccess. If I list the 2 rules 1 after another only the first one works. My page is set up to take 1 or 2 parameters so I need something that will handle a variable number of parameters.

    My hope was the using the second entry alone (the one that caters for 2 parameters) would handle a scenario where you pass either 1 or 2 parameters but this isn't the case. It only works when 2 parameters are passed. If only one is passes nothing is picked up!

    Any help appreciated.


Advertisement