为分层类别编写 .htaccess mod 重写

发布于 2024-09-01 21:03:36 字数 458 浏览 2 评论 0原文

我需要重写我的分类广告目录的网址

我有 4 种类型的链接

/City ==>显示城市/City/Cat1中的所有广告

==> 中的所有广告

显示城市 + 类别/City/Cat1/Cat2 ==> 显示在城市 + 类别 1 + 类别 2 中添加广告

/City/Cat1/Cat2/Ad-id ==>显示广告本身并传递 cat1 cat2 和 city 变量

原始隐藏网址应为 index.php?city=alexandria&cat1=cars&cat2=bikes&adid=EWSw22d

你能帮我吗为此结构编写.htaccess

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 .htaccess for this structure

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拥有 2024-09-08 21:03:36

您可能应该将第一个重写规则替换为 rewritecond,但想法是这样的:

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

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
网白 2024-09-08 21:03:36

我将使用单个规则将所有不存在的请求恢复到索引 PHP,然后解析那里的请求字符串。像这样

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

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]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文