Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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
Regex 如何将所有url请求重定向到index.php/path/variables,以img/开头的请求除外?_Regex_Mod Rewrite_Rewrite_Apache - Fatal编程技术网

Regex 如何将所有url请求重定向到index.php/path/variables,以img/开头的请求除外?

Regex 如何将所有url请求重定向到index.php/path/variables,以img/开头的请求除外?,regex,mod-rewrite,rewrite,apache,Regex,Mod Rewrite,Rewrite,Apache,我有一些简单的重写规则,可以将所有路径变量重定向到/index.php。但现在我想为所有/img/(*)URL做一个例外 这里有一个片段。请告知 RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d Rewr

我有一些简单的重写规则,可以将所有路径变量重定向到/index.php。但现在我想为所有/img/(*)URL做一个例外

这里有一个片段。请告知

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1 [L]
我尝试将
重写规则^img/(*)img/index.php/$1[L]
添加到最后一行catchall的上方,但它不起作用

我想要的结果是这样的:

url      --> script / path variables
====================================
/abc/def --> /index.php/abc/def
/img/abc --> /img/index.php/abc

你能给我指出正确的方向吗?

你不仅需要将其添加到最后一条catchall线的上方,还需要保留catchall所需的条件,并同样为你自己的
/img/
路由复制这些条件:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^img/(.*) img/index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1 [L]