1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Pretty URL with added parameter

Discussion in 'PHP' started by medialab, Dec 13, 2019.

  1. #1
    Hey Everyone,

    I have an .htaccess file that redirects a page to a pretty URL, very basic and pretty standard, the problem I am having is I would like to put a sort variable into the URL once on the page, I know there's an easy answer to this but I can't seem to find it.

    If I append a variable at the end of the pretty URL php won't read via $_GET,

    website . com / category / page? sort=new <-- This doesn't work.

    Here's the .htaccess code, again very simple, but I can't add the sort into .htaccess either as I am trying to sort 4 different ways, and I don't know the length of the page title for the pretty url part.

    RewriteRule ^business/([a-z0-9-]+)$ list.php?category=10&slug=$1

    ANY IDEAS??? THANKS!
     
    medialab, Dec 13, 2019 IP
  2. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #2
    PHP is not reading ?sort=new because because htaccess is not passing it to the actual PHP file that is doing the processing.

    Try this htaccess code:


    RewriteRule ^business/([a-z0-9-]+)/([a-z]+)$ list.php?category=10&slug=$1&sort=$2
     
    JEET, Dec 14, 2019 IP
  3. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #3
    Please note that you need to have both old and new lines in the htaccess, otherwise older URLs will stop showing the page. So have both like this:


    RewriteRule ^business/([a-z0-9-]+)$ list.php?category=10&slug=$1

    RewriteRule ^business/([a-z0-9-]+)/([a-z]+)$ list.php?category=10&slug=$1&sort=$2

    Have them both in htaccess file, in same order.

    You will also need to modify your PHP code to get the sort parameter from your new URLs.

    Currently its only taking that slug parameter and ignoring the rest if passed...
     
    JEET, Dec 14, 2019 IP