phpwordpress.htaccessfriendly-url

How To Clean Up A URL From ? to /


I need help cleaning up my URLs from this:

http://cocrele.com/service-areas/?state=arkansas&city=amity

to this:

http://cocrele.com/service-areas/arkansas/amity/

I tried a few .htaccess tricks but nothing is sticking using WordPress.


Solution

  • Try this out, this will search for the string in the url, if it contains what you want then you can just set the get parameters based off of that. Very easy fix.

    $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    
    if (strpos($url,'amity') !== false) {
    //Do functions, etc. if it contains amity
        $_GET['state'] = 'arkansas';
        $_GET['city'] = 'amity';
    
    } else {
        //Don't do anything
    }