Htaccess rewriterule / a to / a / b

时间:2015-08-13 09:56:07

标签: php regex apache .htaccess mod-rewrite

我尝试从目录/a/准备重写规则到子文件夹/a/b/,但我收到的信息是我的重写规则是循环的,所以我收到的output URLlocalhost/a/b/a/b/a/a/b为了请求localhost / a /。我想收到:

localhost/a and rewrite to localhost/a/b

我试试:

RewriteEngine On
RewriteCond %{REQUEST_URI} !=/a/b
RewriteRule ^/a(.*)$ /a/b/$1 [L]

1 个答案:

答案 0 :(得分:2)

内部/a/.htaccess有此规则:

RewriteEngine on
RewriteBase /a/

RewriteRule ^((?!b/).*)$ b/$1 [NC,L,R=302]

如果要从此重定向跳过实际文件/目录,请使用:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?!b/).*)$ b/$1 [NC,L,R=302]