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 浏览文件夹的图库,视频,图片之类的怎样删除?
  • ¥15 怎么把512还原为520格式
  • ¥15 MATLAB的动态模态分解出现错误,以CFX非定常模拟结果为快照
  • ¥15 求高通平台Softsim调试经验
  • ¥15 canal如何实现将mysql多张表(月表)采集入库到目标表中(一张表)?
  • ¥15 wpf ScrollViewer实现冻结左侧宽度w范围内的视图
  • ¥15 栅极驱动低侧烧毁MOSFET
  • ¥30 写segy数据时出错3
  • ¥100 linux下qt运行QCefView demo报错
  • ¥50 F1C100S下的红外解码IR_RX驱动问题