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
.htaccess :
php (simple way with key=>value pairs):
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:
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:
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).