How do I regex htaccess for my search query
Example my URL
http://domain.com/search.php?s=search&w=state&t=town&c=category&p=1
- s = search keyword
- w = region
- t = town
- c = category
- p = paging
What I have done for now in my .htaccess
is
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/$ /search.php?s=$1&w=$2&t=$3&c=$4&p=$5 [L]
And the URL will be
http://domain.com/search/keyword/region/town/category/1/
Question
How do I rewrite my .htaccess to make my URL can be global query.
Example s=bmw+5+series&w=&t=&c=
http://domain.com/search/bmw-5-siries/
Example s=bmw+5+series&w=&t=&c=car
http://domain.com/search/car/bmw-5-siries/
Example s=bmw+5+series&w=manchester&开发者_如何学Go;t=&c=car
http://domain.com/search/manchester/car/bmw-5-siries/
or other output as long in the queries term.`
This is possible?
The easiest method would be to edit the SEO URLs to prepend the search term with a character to identify the searched term.
i.e.
/search/bmw-5-series/r/Manchester/c/Car or /search/bmw-5-series/c/Luxury
and use the variables along with a RewriteCond to identify which RewriteRule to apply.
With your current method, it would be hard to identify if the third item (eg. car) is a town or the category or something else, unless you have fixed rules. (i.e If Town is passed then the Region will definitely be passed so you can write a different set of rules to handle each condition instead of the single rule you have now)
eg.
RewriteRule ^([^/]*)/([^/]*)/$ /search.php?s=$1&w=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)//$ /search.php?s=$1&w=$2&t=$3 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/$ /search.php?s=$1&w=$2&t=$3&c=$4 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/$ /search.php?s=$1&w=$2&t=$3&c=$4&p=$5 [L]
精彩评论