ds78662302 2017-03-12 13:44
浏览 59
已采纳

htaccess重定向到wamp本地地址

I have an already online hosted website which I have downloaded and configured for wamp. The only problem which occurred is that if I click on any link on my local website I will get redirected to my online website.

Unfornutally I cannot set up my htaccess so that it's changing the online links to the local server.

So for instance:

Having a link on a site which redirects to www.example.com/blog should be rewritten to redirect to example.dev/blog.

For that I have tried something like that:

RewriteEngine on

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

But it does not work.

EDIT: A more in depth example:

I have a website which address is: www.example.com its local wamp address is example.dev. Now I have a link <a href="http://www.example.com/shop.html">Shop</a> within a index.html of the local example.dev root. And now I need a way to redirect http://www.example.com/shop.html to http://example.dev/shop.html. This should be apply to all sub pages not only for shop. Also for style sheets etc.

  • 写回答

1条回答 默认 最新

  • douxiyi2418 2017-03-12 15:51
    关注

    Two things must be changed in the rules

    • HTTP_HOST contains only the host, nothing else. So the condition should rather be

      RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
      
    • The target will be interpreted as a file system path. To redirect it to another host, you must specify a complete URL including the protocol (http)

      RewriteRule ^(.*)$ http://example.dev/$1 [R,L]
      

    Another approach to redirect one site to another wholesale, can be done by Redirect

    Redirect /blog http://example.dev/blog
    

    or doing this with all requests

    Redirect / http://example.dev/
    

    Looking at your update, it seems you don't need .htaccess at all. You must rather change the relevant links to either

    <a href="http://www.example.dev/shop.html">Shop</a>
    

    or better yet, don't use absolute URLs

    <a href="/shop.html">Shop</a>
    

    Similar for style sheets or Javascript files.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥40 selenium访问信用中国
  • ¥15 电视大赛投票系统的c语言代码怎么做
  • ¥20 在搭建fabric网络过程中遇到“无法使用新的生命周期”的报错
  • ¥15 Python中关于代码运行报错的问题
  • ¥500 python 的API,有酬谢
  • ¥15 软件冲突问题,软件残留问题
  • ¥30 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥50 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥15 alpha101因子里哪些适合crypto?
  • ¥15 ctrl win alt 键一直触发
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部