Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8928713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:30:35+00:00 2026-06-15T08:30:35+00:00

I just spent a few hours looking around here but didn’t really find a

  • 0

I just spent a few hours looking around here but didn’t really find a solution.

I currently have typical query string like;

 http://www.site/jobs/results.php?keyword=Accounting+%26+Finance&type=10&state_id=130&location=NSW&order=1&page=1

which Id like to rewrite to

 http://www.site/jobs/find/accounting-finance/NSW/free-jobs/1/?order=1

but I don’t know what params will sent, that will depend on what the user does, filters,categories,orders etc

I would like to keep it simple and parse the url in PHP and use a simple rewrite rule, but then I need key/value pairs so I know which value belongs to which param something like;

http://www.site/jobs/find/keyword/accounting-finance/state/NSW/type/free-jobs/page/1/?order=1

I’m told that is not a good option for seo.

Apart from writing many different rules in .htacces to cover all the scenarios can you suggest a better way to approach this

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:30:38+00:00Added an answer on June 15, 2026 at 8:30 am

    .htaccess :

    RewriteEngine on
    # skip rewriting if file/dir exists (optionally)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # rewrite all to results.php
    RewriteRule . results.php
    

    php (simple way with key=>value pairs):

    // current URI (/jobs/find/keyword/accounting-finance/state/NSW/type/free-jobs/page/1/?order=1)
    $path = $_SERVER['REQUEST_URI'];
    
    // remove base path (/jobs)
    if (($len = strlen(basename($_SERVER['SCRIPT_FILENAME'])))) 
        $path = substr($len, $path);
    
    // remove GET params (?order=1)
    if (false !== ($pos = strpos($path, '?'))) 
        $path = substr($path, 0, $pos);
    
    $path = explode('/', trim($path, '/'));
    
    // extract action (or whatever 'find' is)
    $action = array_shift($path);
    
    // make key => value pairs from the rest
    $params = array();
    for ($i = 1, $c = count($path) ; $i < $c ; $i += 2) {
        $params[urldecode($path[$i - 1])] = urldecode($params[$i]);
        // or put it to GET (only remember that it will overwrite already existing values)
        //$_GET[urldecode($path[$i - 1])] = urldecode($params[$i]);
    }
    

    you can modify this script to achieve values only without keys, but here comes the question – is it possible to determine if value should be one key or another? If params are always on same position and you can only get less or more of them, then its pretty easy:

    // skip this step from previous example
    //$action = array_shift($path);    
    
    $params = array(
        'action' => null,
        'keyword' => null,
        'state' => null,
        'type' => null,
        'page' => null,
    );
    $keys = array_keys($params);
    for ($i = 0 , $c = min(count($path), count($keys) ; $i < $c ; ++$i) {
        $params[$keys[$i]] = urldecode($path[$i]);
    }
    

    But if you don’t know which param is on which position then things are going to be more complex. You would need to do some checks on every param and determine which one it is – if all of those values are selected from some known lists of values then it also won’t be very difficult, for example:

    $params = array(
        'action' => null,
        'keyword' => null,
        'state' => null,
        'type' => null,
        'page' => null,
    );
    $params['action'] = array_shift($path);
    $keys = array_keys($params);
    foreach ($path as $value) {
        if (is_numeric($value)) $params['page'] = intVal($value);
        else {
            $key = null;
            // that switch is not very nice - because of hardcode
            // but is much faster than using 'in_array' or something similar
            // anyway it can be done in many many ways
            switch ($value) {
                case 'accounting-finance' :
                case 'keyword2' :
                case 'keyword3' :
                    $key = 'keyword';
                    break;
                case 'NSW' :
                case 'state2' :
                    $key = 'state';
                    break;
                case 'type1' :
                case 'type2' :
                case 'type3' :
                    $key = 'type';
                    break;
                // and so on...
            }
            if ($key === null) throw new Exception('Unknown value!');
            $params[$key] = $value;
        }
    }
    

    You can also to try write some really complex regexes in .htaccess, but IMO it is not a place for that – apache should match request with correct endpoint in your application and run it, its not place for extended params logic (if anyway it will go to the same place in your app). Also its much more convenient to keep that logic in app – when you’re changing something you can do that in app code without need of changing anything in htaccess or apache config (in productional environment I’m mostly moving .htaccess contents to apache config and turning off .htaccess support – that gives some speedup when apache is not searching for those files, but any change require apache restart).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, I have already spent the past few hours trying to find a solution
I would not say I wasted my time, but spent around few hours changing
I would not say I wasted my time, but spent around few hours changing
I have spent quite a few hours reading and learning about LINQ to XML , but
I have spent many hours looking into this and I still can't find a
Just spent a few hours trying to get my head around dependency properties (finding
I've spent the past few hours searching, but can't seem to find the answer.
I just spent 5 hours by checking Google gadgets websites and FAQs, but I
I just spent a few hours pulling my hair out over this. I'm trying
I've spent a few hours playing around with this one, without success so far.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.