Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess htaccess重写url的参数等于0_.htaccess_Url Rewriting - Fatal编程技术网

.htaccess htaccess重写url的参数等于0

.htaccess htaccess重写url的参数等于0,.htaccess,url-rewriting,.htaccess,Url Rewriting,我想换衣服 detail.php?cid=$category&ccid=$category2&cccid=$category3&fid=$id&ftitle=$titleseo 到 但如果其中一个参数等于0,则该参数不应可见。 因此,如果$category=0,url应为: detail/$category2/$category3/$id/$titleseo detail/$category/$category3/$id/$titleseo 如果$categ

我想换衣服

detail.php?cid=$category&ccid=$category2&cccid=$category3&fid=$id&ftitle=$titleseo

但如果其中一个参数等于0,则该参数不应可见。 因此,如果
$category=0
,url应为:

detail/$category2/$category3/$id/$titleseo
detail/$category/$category3/$id/$titleseo
如果
$category2=0
,则url应为:

detail/$category2/$category3/$id/$titleseo
detail/$category/$category3/$id/$titleseo

htaccess中的重写规则是否可能实现这一点?如果是,这应该是什么样子?

考虑到
/$category/$category2/$category3/
已给定名称
/$id/$titleseo
已修复,您可以使用此选项:

RewriteEngine On
RewriteBase  /
RewriteRule ^detail/(\$category)?/?(\$category2)?/?(\$category3)?/?(\$id)/(\$titleseo)$  - [E=PASS:cid=$1&ccid=$2&cccid=$3&fid=$4&ftitle=$5]
RewriteCond %{ENV:PASS} (.*)(&)[a-z]+=&(.*)$|[a-z]+=&(.*)$
RewriteRule  ^      details.php?%1%2%3%4 [L]
RewriteCond %{QUERY_STRING} (.*)(&)[a-z]+=&(.*)$|[a-z]+=&(.*)$
RewriteRule  ^      details.php?%1%2%3%4 [L]
RewriteCond %{ENV:PASS} ^(.+)$
RewriteRule  ^      details.php?%1 [L]
一般来说,这是:

RewriteEngine On
RewriteBase /
RewriteRule ^detail/([^/]+)?/?([^/]+)?/?([^/]+)?/?(\$id)/(\$titleseo)$  - [E=PASS:cid=$1&ccid=$2&cccid=$3&fid=$4&ftitle=$5]
RewriteCond %{ENV:PASS} (.*)(&)[a-z]+=&(.*)$|[a-z]+=&(.*)$
RewriteRule  ^      details.php?%1%2%3%4 [L]
RewriteCond %{QUERY_STRING} (.*)(&)[a-z]+=&(.*)$|[a-z]+=&(.*)$
RewriteRule  ^      details.php?%1%2%3%4 [L]
RewriteCond %{ENV:PASS} ^(.+)$
RewriteRule  ^      details.php?%1 [L]
根据上述规则,首先通过捕获任何请求来创建环境,以细节开始,以
/$id/$titleseo
结束,然后检查ENV值以查看哪个值有/没有值,最后相应地重定向它

这两个规则适用于三个级别的类别如果您需要更多,您可以编辑如下规则:


重写规则^detail/
之后添加此
([^/]+)?/?
,然后
[E=PASS:cid=$1&ccid=$2&cccid=$3&cccccccccid=$4&fid=$5&ftitle=$6]
最后,您可以比较此规则和前一规则之间的差异,以获得一个标准,最后将
%5
添加到
/details.php?%1%2%3%4[L]
像这样的
/details.php?%1%2%3%4%5[L]
等等。

到目前为止没有从Mohammed那里得到代码,但是使用了

RewriteRule ^detail/?([0-9a-zA-Z]+)?/?([0-9a-zA-Z]+)?/?([0-9a-zA-Z]+)?/([0-9a-zA-Z]+)/([0-9a-zA-Z]+) detail.php?cid=$1&ccid=$2&cccid=$3&fid=$4&&ftitle=$5

非常感谢穆罕默德,不知为什么这对我不起作用。如果我输入detail/schlagzeilen/algemein/0/497/kitas bahnen muellabfuhr hier wird ab dienstag in der region gestreikt,我会得到错误404。我目前有以下规则可以使用:RewriteRule^detail/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)detail.php?cid=$1&cccid=$3&fid=$4&&ftitle=$5,但就像我说的那样,它也把0的类别放在了,我想把它们去掉。“我希望你能帮助我。”斯皮克维尔将RewriteBase/置于RewriteEngine之下,然后再次测试