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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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对2个不工作的文件使用相同的规则_.htaccess - Fatal编程技术网

.htaccess Htaccess对2个不工作的文件使用相同的规则

.htaccess Htaccess对2个不工作的文件使用相同的规则,.htaccess,.htaccess,我正在尝试使用htaccess文件创建友好的分页 但它不起作用,我想我对文件使用了错误的规则 查看下面我的代码 Options +FollowSymLinks RewriteEngine on RewriteCond %{THE_REQUEST} \s/+search\.php\?q=([^\s&]+) [NC] RewriteRule ^ /search/%1/? [R=301,L] RewriteRule ^search/$ search/%1 [L,R=301,NC] Rewr

我正在尝试使用htaccess文件创建友好的分页

但它不起作用,我想我对文件使用了错误的规则

查看下面我的代码

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{THE_REQUEST} \s/+search\.php\?q=([^\s&]+) [NC]
RewriteRule ^ /search/%1/? [R=301,L]

RewriteRule ^search/$ search/%1 [L,R=301,NC]
RewriteRule ^search/(.*)/$ search.php?q=$1 [L,NC]

RewriteRule ^new/(.*)$ new.php?page=$1 [L,NC]
RewriteRule ^(.*)/$ cat.php?id=$1 [NC]

RewriteRule ^(.*)/(.*)/$ cat2.php?id=$1&page=$2 [NC,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ post.php?id=$1 [NC]
一切正常,只有
cat2.php
不工作。
如何修复它?

您需要在两个cat规则之间切换顺序<代码>(*)匹配所有内容,包括斜杠,因此它将始终匹配cat2匹配的任何内容。尝试交换订单并包含
L
标志:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{THE_REQUEST} \s/+search\.php\?q=([^\s&]+) [NC]
RewriteRule ^ /search/%1/? [R=301,L]

RewriteRule ^search/$ search/%1 [L,R=301,NC]
RewriteRule ^search/(.*)/$ search.php?q=$1 [L,NC]

RewriteRule ^new/(.*)$ new.php?page=$1 [L,NC]
RewriteRule ^(.*)/(.*)/$ cat2.php?id=$1&page=$2 [L,NC,QSA]
RewriteRule ^(.*)/$ cat.php?id=$1 [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ post.php?id=$1 [NC]