du9826 2011-12-20 14:45
浏览 42

重定向到域根但存储原始URL请求

Hi what I want to do is take an url like: http://mydomain.com/google.com and parse it so it opens google.com in an iframe. The goal is to be able to open any site on mydomain.com in iframe but have users submit their desired site with http://mydomain.com/<somesite> for example: http://mydomain.com/youtube.com would open youtube in iframe. The problem is that appending the site to the url like that obviously returns 404 not found. I'm guessing some htaccess magic is needed here but I am no good with it.

So how would I accomplish this?

  • 写回答

1条回答 默认 最新

  • douzhangcuo2174 2011-12-20 14:51
    关注

    Yup, you need a .htaccess magic. Try:

    RewriteEngine on
    RewriteBase /
    RewriteRule ^u/(.+)? http://$1 [L]
    

    That is:

    If you find a request for /u/something, redirect it to http://something.

    And then in your HTML:

    <a href="http://yourdomain.com/u/google.com" target="yourIframeName">Link</a>
    

    I placed the /u/ part because without that it's hard for your website to make other page work apart from index.php. We need a way to distinguish between normal URLs and iframe redirections.

    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计