我的Php mvc应用程序中有一个目录结构,目前就像这样
/site.com
.htaccess
index.php
/models
/views..
/controllers..
/resources..
/images..
/misc..
logo.png
/products..
product_image1.jpg
/js..
/css..
我想将资源文件夹移动到自己的子域,因此结构类似于
/site.com
.htaccess
index.php
/models
/views..
/controllers..
/resources.site.com
/images..
/misc..
logo.png
/products..
product_image1.jpg
/js..
/css..
我需要知道将资源文件夹中任何内容的请求重定向到新子域的重写规则。
我已尝试过这条规则以及其他一些规则,但它无效。
RewriteEngine On
RewriteBase /resources
RewriteCond %{HTTP_HOST} ^resources$ [NC]
RewriteRule ^(.*)$ http://localhost/resources.site.com/$1 [L]
非常感谢任何帮助。谢谢
答案 0 :(得分:2)
你的规则有点混乱。如果您要将资源目录 重新写入 新域,则不希望将其中一个条件作为新域的请求。在htaccess文件中尝试这样的事情:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^resources\.site\.com$ [NC]
RewriteRule ^resources/(.*)$ http://resources.site.com/$1 [R=301,L]
这样,当您请求http://site.com/resources/images/misc/logo.png时,您将被重定向到http://resources.site.com/images/misc/logo.png