有没有办法重写这些URL?

时间:2013-07-16 16:46:12

标签: php .htaccess

有没有办法可以访问文件夹中的所有图片:

www.example.com/image/

通过这样的网址:

static.example.com/image/

例如,图像

www.example.com/image/hello.jpg

只能通过以下方式访问:

static.example.com/image/hello.jpg

2 个答案:

答案 0 :(得分:0)

static.example.comAlias / image /设置虚拟名称主机到您想要的目录。

然后在虚拟主机中设置<Location>部分,以www.example.comDeny访问它。

答案 1 :(得分:0)

假设您已经创建了子域:static.example.com

www.example.com主机上,通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在.htaccess目录下的DOCUMENT_ROOT中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?\.example\.com$ [NC]
RewriteRule ^(image(?:/.*|))$ http://static.example.com/$1 [L,R=301,NC]