.htaccess 在任何子文件夹中建立索引时重新路由htaccess

.htaccess 在任何子文件夹中建立索引时重新路由htaccess,.htaccess,mod-rewrite,url-rewriting,.htaccess,Mod Rewrite,Url Rewriting,我目前在htaccess中设置了以下重写: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]*)/([^/]*)/(.*)$ index.php?controller=$1&cmd=$2&params=$3 [L,QSA] RewriteRule ^([^/]*)/([^/]*)$ index.php?controller=$1&cmd=$2

我目前在htaccess中设置了以下重写:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/(.*)$ index.php?controller=$1&cmd=$2&params=$3 [L,QSA]
RewriteRule ^([^/]*)/([^/]*)$ index.php?controller=$1&cmd=$2 [L,QSA]
RewriteRule ^([^/]*)$ index.php?controller=$1 [L,QSA]
例如blog只是重写为index.php?controller=blog,或者blog/show/32重写为index.php?controller=blog&cmd=show¶ms=32等等


我想把我所有的站点转移到一个名为testing的子文件夹中,所以需要更新我的htaccess来适应。不担心重新路由到文件夹,即我不担心键入www.example.com并将其登录到/testing/index.php,我想键入www.example.com/testing/并将其登录到index.php,它会这样做,但其他规则似乎会被打破。

将此规则保留在根目录中。htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/(.*)$ index.php?controller=$1&cmd=$2&params=$3 [L,QSA]
RewriteRule ^([^/]*)/([^/]*)$ index.php?controller=$1&cmd=$2 [L,QSA]
RewriteRule ^([^/]*)$ index.php?controller=$1 [L,QSA]
RewriteEngine On

RewriteRule ^((?!testing/).*)$ testing/$1 [L,NC]
将此规则保留在/testing/.htaccess`:

RewriteEngine On
RewriteBase /testing/

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/([^/]+)/(.+)$ index.php?controller=$1&cmd=$2&params=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?controller=$1&cmd=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?controller=$1 [L,QSA]

如果将此.htaccess与文件一起移动到子文件夹中,它将正常工作。你不需要改变任何事情。如果.htaccess中有
RewriteBase
指令,则必须对其进行更新以反映新路径