dongli1887 2015-03-22 21:13
浏览 183
已采纳

CDN URL到根文件夹/防止重复内容?

For a image gallery I have to install a CDN Domain.

Default Domain:

http://www.example.com
Apache folder: /html/mywebsite

CDN Domain:

http://cdn.example.com
Apache folder: /html/mywebsite

The CDN Domain need the same Apache folder for url rewrite reasons etc.

Problem:

http://cdn.example.com
and
http://www.example.com

open the same website and this is bad. I cant rewrite (301) from cdn to www because I have to serve the images from the CDN. Also I cant use a 403:

RewriteCond %{HTTP_HOST} ^cdn\.example\.com$ [NC]
RewriteRule .* / [F]

because image urls from the cdn

http://cdn.example.com/images/test.jpg

get also a 403. Is it possible to make a 403 only for the root folder and not for subfolders or do you have a better idea?

btw. robots.txt is also bad, because images from the cdn should be indexed. A htaccess solution would be great.

  • 写回答

2条回答 默认 最新

  • dongruolin5324 2015-03-23 06:26
    关注

    If you only want the root (and any documents in the root) of cdn.example.com to go to www.example.com and each domain uses a separate VirtualHost, you can use something as simple as

    RedirectMatch permanent ^/?(.+\.php)$ http://www.example.com/$1
    

    in the VirtualHost container for cdn.example.com. Obviously, you can tweak the regular expression to match your site's files.

    See the Apache docs for some reasons why this is preferable to using mod_rewrite. It's simpler, easier to maintain, and in many cases will result in better performance.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决