如何使 htaccess 代码与参数一起工作

问题描述 投票:0回答:1
  1. 大家好

我正在编辑 htaccess 文件

我的网址是

cricf.com cricket-article?cardid=3730

我使用下面的代码来重写URL

RewriteEngine on
RewriteCond %{THE_REQUEST} cricket-article.php
RewriteRule (.*).php$ /$1 [L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule cricket-article cricket-article.php [L]

它正在工作。但我找不到 如何使用此代码制作如下例所示的 URL。

cricf.com/cricket-article/cardid/3730

有人可以帮助我吗?

.htaccess url-rewriting
1个回答
0
投票

使用您显示的示例,请尝试以下操作。确保在测试之前清理浏览器缓存。

RewriteEngine ON

##Using THE_REQUEST for catching references and using them later on.
RewriteCond %{THE_REQUEST} \s/(cricket-article)/(cardid)=(\d+)\s [NC]
RewriteRule ^ /%1/%2/%3? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(cricket-article)/(cardid)/(\d+)/?$ $1.php?$2=$3 [QSA,NC,L]
© www.soinside.com 2019 - 2024. All rights reserved.