开发者

Writing .htaccess mod rewrite for hierarchical categories

开发者 https://www.devze.com 2022-12-30 07:11 出处:网络
i need to rewrite urls for my classified ads directory i have 4 types of links /City==> display all ads in city

i need to rewrite urls for my classified ads directory

i have 4 types of links

/City ==> display all ads in city

/City/Cat1 ==> display all ads in city + category

/City/Cat1/Cat2 ==> display add ads in city + category 1 + category 2

/City/Cat1/Cat2/Ad-id ==> display the ad itself and pass cat1 cat2 and city variables

original hidden url should be index.php?city=alexandria&cat1=cars&cat2=bikes&adid=EWSw22d

Can you please help me writing开发者_如何学C .htaccess for this structure


You should probably replace the first rewrite rule for a rewritecond, but this is the idea:

RewriteEngine on
RewriteRule ^index.php index.php [NE,QSA,L]
RewriteRule ^(.*?)(?:/(.*?)(?:/(.*?)(?:/(.*))?)?)?$ index.php?city=$1&cat1=$2&cat2=$3&adid=$4


I'd make it with single rule to revert all unexisting requests to the index PHP and then parse the request string there. Smth like this

RewriteEngine on
RewriteBase /
RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond  %{REQUEST_FILENAME} !-d
RewriteRule  ^(.*)$ index.php?query=$1 [QSA,L]
0

精彩评论

暂无评论...
验证码 换一张
取 消