Apache htaccess再次-特殊url重写到子文件夹
我希望有人能帮助我,因为我被困在这里: 域名-test.site.com 文档根==/www/test 所有内容(CMS)位于/www/test/web 当我键入地址栏时,我需要: 1) test.site.com/*-站点从/www/test/web打开,地址栏保留URL“test.site.com/*” 2) 键入test.site.com/web/*-相同的行为-站点从web打开,URL更改为“test.site.com/*” 3) 异常-type test.site.com/folder1-从/www/test/folder1打开页面 我可以通过以下方式重定向到“web”子文件夹: .htacesss在/www/test中:Apache htaccess再次-特殊url重写到子文件夹,apache,.htaccess,redirect,rewrite,subdirectory,Apache,.htaccess,Redirect,Rewrite,Subdirectory,我希望有人能帮助我,因为我被困在这里: 域名-test.site.com 文档根==/www/test 所有内容(CMS)位于/www/test/web 当我键入地址栏时,我需要: 1) test.site.com/*-站点从/www/test/web打开,地址栏保留URL“test.site.com/*” 2) 键入test.site.com/web/*-相同的行为-站点从web打开,URL更改为“test.site.com/*” 3) 异常-type test.site.com/folder
RewriteCond %{HTTP_HOST} ^test.site.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.test.site.com$
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]
但它只适用于1)要求。
2) 3)不起作用。
至于3)我可以看到,每个请求都将被重定向到“web”子文件夹。对于第二个要求,您需要一个额外的规则将/web重定向到/root 大概是这样的:
RewriteCond %{THE_REQUEST} /web/([^\s]*) [NC]
RewriteRule ^ /%1 [NC,L,R]
上面的规则将匹配以/web/foo开头的任何请求,并将请求重定向到/foo
对于第三个,您需要RewriteCond将/folder1从RewriteRule中排除
RewriteCond %{REQUEST_URI} !^/folder1
重写
RewriteCond %{THE_REQUEST} /web/([^\s]*) [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{HTTP_HOST} ^(www\.)?test.site.com$ [NC]
RewriteCond %{REQUEST_URI} !^/folder1 RewriteRule ((?!web).*) /web/$1 [NC,L]