apache - htaccess 允许域只提供图像

标签 apache .htaccess redirect seo

我这辈子都无法解决这个问题。

我有一个主域名,托管着一个繁忙的网站。 (domain1.com)

我有第二个域,它使用来自域 #1 的内容。要链接第二个站点上的图像,我想使用 images.domain2.com。

images.domain2.com 已设置为 domain1.com 上的别名。

所以现在如果有人访问 images.domain2.com 他们会看到 domain1.com 的内容,我不希望人们看到这个。 (重复内容)。

不过,如果有人请求 images.domain2.com/images/image1.jpg,我希望它能正常工作。

这有意义吗?

最佳答案

试试这个

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^images\.domain2\.com [NC] 

    RewriteCond %{REQUEST_FILENAME} !\.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$
    RewriteRule ^(.*)$ domain2.com/$1 [L]
</IfModule>

关于apache - htaccess 允许域只提供图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14377483/

相关文章:

apache - mod_auth_basic在https下是明文传输的吗?

php - 我可以在 guest 操作系统上设置使用 Windows 主机中的文件的 WAMP 虚拟机吗?

html - 将 index.html 设置为默认值,但如果输入则允许访问 index.php

javascript - Laravel 重定向不起作用

apache - mod_rewrite : remove trailing slash (only one! )

perl - 如何在 perl 中禁用 stdout 重定向到文件缓冲?

php - 在源服务器上设置 Access-Control-Allow-Origin header

php - Docker 服务 php-fpm 容器之间的 cURL 导致 "Connection refused"

apache - .htaccess 重定向到新域

.htaccess - 具有 .htaccess 和 mod_rewrite 的静态 HTML 文件的语义 URL