我正在尝试根据子域名字符串重定向图像,css,js和其他一些文件夹:
WWW:
所有其他子域名:
所有其他请求必须通过index.php
进行路由到目前为止我所做的部分工作是:
#THIS BLOCK WORKS
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L] # <--DON'T KNOW ABOUT THESE FLAGS
# SUBDOMAIN - THIS PART WORKS
RewriteCond %{HTTP_HOST} !^www\.subdomain\.[a-z] <--# ADDED [a-z] .dev or .com
RewriteRule ^css/(.*)$ /app/css/$1 [R,NC,L]
RewriteRule ^js/(.*)$ /app/js/$1 [R,NC,L]
RewriteRule ^assets/(.*)$ /app/assets/$1 [R,NC,L]
RewriteRule ^images/(.*)$ /app/images/$1 [R,NC,L]
RewriteRule ^uploads/(.*)$ /app/uploads/$1 [R,NC,L]
# OR
# WWW - THIS PART WORKS
RewriteCond %{HTTP_HOST} ^www\.subdomain\.[a-z] <--# ADDED [a-z] .dev or .com
RewriteRule ^css/(.*)$ /site/css/$1 [R,NC,L]
RewriteRule ^js/(.*)$ /site/js/$1 [R,NC,L]
RewriteRule ^assets/(.*)$ /site/assets/$1 [R,NC,L]
RewriteRule ^images/(.*)$ /site/images/$1 [R,NC,L]
RewriteRule ^uploads/(.*)$ /site/uploads/$1 [R,NC,L]
# BUT NOT TOGETHER
RewriteRule ^.*$ index.php [NC,L]
我不能让这两套规则一起工作。
我希望有类似的东西:
RewriteCond%{HTTP_HOST}!^ www.domain。[a-z]
RewriteRule ^(。?)。(php | css | js | jpg | jpeg | png | pdf)/(。)$ / app / css / $ 1 [L]
提前谢谢!
答案 0 :(得分:0)
只有一个不眠之夜,我找到了它!
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{HTTP_HOST} !^www\.domain\.[a-z]
RewriteRule ^(css|js|images|assets)/(.*)$ /app/$1/$2 [R,NC,L]
RewriteCond %{HTTP_HOST} ^www\.domain\.[a-z]
RewriteRule ^(css|js|images|assets)/(.*)$ /site/$1/$2 [R,NC,L]
RewriteRule ^.*$ index.php [NC,L]