Apache Rewrite:%{HTTP_HOST} 目录中的域特定图库图像
在共享网络托管上,我的软件支持多个域(所有域都指向同一个 public_html 根目录)。每个域都有自己的画廊(在画廊目录中)。由于多个域不能在所有站点的同一目录中拥有自己的资源(例如图像),因此我有与每个 HTTP 主机名匹配的根目录。这是目录结构的样子...
/public_html/
/public_html/.htaccess
/public_html/画廊/
/public_html/www.example1.com/gallery/topic_x/image.png
/public_html/www.example2.com/gallery/topic_y/image.jpg
/public_html/www.example3.com/gallery/topic_z/image.gif
请求...
...需要重写为...
/public_html/www.example1.com/gallery/topic_x/image.png
这需要使用 .htaccess 文件来完成,如上所述,HTTP 主机匹配目录中没有 .htaccess 文件 (/public_html/www.example1 .com/.htaccess 不存在)。
我一直在尝试对以下内容进行多次修改......
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(gallery)(/.+\.(gif|jpg|png))$ %{HTTP_HOST}$1$2 [L,NC]
但没有成功。
On shared web-hosting my software supports multiple domains (all domains point to the same public_html root directory). Each domain has it's own gallery (in the gallery directory). Since multiple domains can not have their own resources (e.g. images) in the same directory for all sites I have root directories that match each HTTP host name. Here is what the directory structure looks like...
/public_html/
/public_html/.htaccess
/public_html/gallery/
/public_html/www.example1.com/gallery/topic_x/image.png
/public_html/www.example2.com/gallery/topic_y/image.jpg
/public_html/www.example3.com/gallery/topic_z/image.gif
A request to...
...needs to be rewritten to...
/public_html/www.example1.com/gallery/topic_x/image.png
This needs to be done using the .htaccess file as is noted above, there are no .htaccess files in the HTTP Host matching directories (/public_html/www.example1.com/.htaccess does not exist).
I have been trying with numerous modifications of the following...
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(gallery)(/.+\.(gif|jpg|png))$ %{HTTP_HOST}$1$2 [L,NC]
...without success.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我有用:
如果你愿意——你可以添加额外的检查来重写,只有当这样的最终图像存在时(虽然我没有测试过这一点):
但即使你的模式也应该有效(至少它通过了测试)——也许 .htaccess 未启用..或者您忘记激活重写引擎(
RewriteEngine On
)?我还建议在激活引擎之前(或之后)添加此行:
或
某些共享托管可能仅适用于第二个,对于某些第一个就足够了。
This one works for me:
If you want -- you can add extra check to rewrite only if such final image is present (although I have not tested this):
But even your pattern should work (at least it passes the test) -- maybe .htaccess is not enabled .. or you forgot to activate rewrite engine (
RewriteEngine On
)?I would also recommend adding this line before (or after) activating engine:
or
Some shared hosting may only work with 2nd, for some 1st is enough.