php - 无法通过 .htaccess 获取 url 字符串中的第 10 个变量

标签 php .htaccess

我想在我的 php 代码中获取 sort_by,但它似乎是返回变量 1 和数字 0 的值。

RewriteRule ^abc/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ search.php?counrty=abc&state=$1&gender=$2&r_city=$3&r_mstatus=$4&r_religion=$5&r_ethnicity=$6&r_cast=$7&r_profession=$8&r_education=$9&sort_by=$10 [NC]

最佳答案

根据Apache文档,对于$NN的值只能是0-9。所以试图获得 $10 是行不通的。您可能需要经历两个重写步骤。所以,也许你使用这样的东西:

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+/[^/]+/[^/]+)/?$ search.php?country=$1&state=$2&gender=$3&r_city=$4&r_mstatus=$5&r_religion=$6&r_ethnicity=$7&r_cast=$8&r_profession=$8&profession_and_education_and_sort=$9 [NC]

RewriteCond %{REQUEST_FILENAME} ^search\.php$
RewriteCond %{QUERY_STRING} ^(country=.*&state=.*&gender=.*&r_city=.*&r_mstatus=.*&r_religion=.*&r_ethnicity=.*&r_cast=.*)&profession_and_education_and_sort=([^/]+)/([^/]+)/([^/]+)
RewriteCond ^search\.php$ search.php?%1&r_profession=%2&r_education=%3&sort_by=%4 [NC,L]

关于php - 无法通过 .htaccess 获取 url 字符串中的第 10 个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12356996/

相关文章:

php - 是否可以通过 [Web] Guard 使用 Laravel 资源?

java - 我如何在 mysql 数据库更新后立即运行脚本(cronjob)

.htaccess - htaccess 重定向 index.php?p=my topic title to/my-topic-title

php - 使用 Apache 和 PHP 分块 gzip 的任何方法

.htaccess - 如何在标题中使用带有 301 的错误文档 404?

php - MongoDB PHP UTF-8 问题

php - 如何在 codeigniter 中使用 FIND_IN_SET() 查询

php - PDO(PHP 数据对象)的缺点

wordpress - 强制非 WWW 但强制 https 跨所有 wordpress 和整个域

.htaccess - 如何在 htaccess 中添加异常