ds78662302 2017-03-12 21: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 23: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.

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

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘