Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

SEO friendly links PHP / htaccess problem

Options
  • 26-04-2015 1:47pm
    #1
    Registered Users Posts: 155 ✭✭


    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