[英]htaccess redirect to wamp local address
I have an already online hosted website which I have downloaded and configured for wamp. 我有一个已经在线托管的网站,我已经下载并配置了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. 不幸的是,我无法设置htaccess,因此它正在更改到本地服务器的在线链接。
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
. 在网站上重定向到
www.example.com/blog
的链接应重写为重定向到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
. 我有一个网址为:
www.example.com
的网站,其本地地址为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. 现在,我在本地
example.dev
根目录的index.html中有一个<a href="http://www.example.com/shop.html">Shop</a>
链接。 And now I need a way to redirect http://www.example.com/shop.html
to http://example.dev/shop.html
. 现在,我需要一种将
http://www.example.com/shop.html
重定向到http://example.dev/shop.html
。 This should be apply to all sub pages not only for shop. 这不仅应适用于商店,而且应适用于所有子页面。 Also for style sheets etc.
也用于样式表等
Two things must be changed in the rules 规则中必须更改两件事
HTTP_HOST
contains only the host, nothing else. HTTP_HOST
仅包含主机,没有其他内容。 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
) 要将其重定向到另一个主机,您必须指定一个完整的URL,包括协议(
http
)
RewriteRule ^(.*)$ http://example.dev/$1 [R,L]
Another approach to redirect one site to another wholesale, can be done by Redirect
将一个站点重定向到另一批发站点的另一种方法可以通过
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. 查看您的更新,看来您根本不需要.htaccess。 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 或更好的是,不要使用绝对URL
<a href="/shop.html">Shop</a>
Similar for style sheets or Javascript files. 样式表或Javascript文件类似。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.