重写htaccess目录以充当外部网站

时间:2017-02-06 09:41:50

标签: apache .htaccess mod-rewrite

所以我有一个网站,例如http://example.com/和另一个网站http://example.myeshop.com/。我想让可访问的网址http://example.com/eshophttp://example.myeshop.com/相同,但不会重定向。此外,当有人使用http://example.com/eshop/contact之类的链接时,它会与http://example.myeshop.com/contact具有相同的效果,依此类推。这是我的.htaccess文件:

IndexIgnore */*

RewriteEngine On

RewriteRule /eshop/(.*) http://example.myeshop.com/$1 [NC]
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/xhtml text/html text/plain text/xml text/javascript application/x-javascript text/css
</IfModule>

FileETag none

但似乎没有奏效。你能帮助我如何实现这样的目标吗?

2 个答案:

答案 0 :(得分:1)

您正在寻找的是mod-proxy。在服务器上启用代理模块,然后您可以使用:

RewriteEngine on

RewriteRule ^eshop/(.*)$ http://example.myeshop.com/$1 [P]

这将在内部将example.com的所有请求发送到example.myeshop.com。如果未启用代理模块,您将收到内部服务器错误。

答案 1 :(得分:0)

如果您有权访问httpd.conf,则可以在httpd.conf文件中使用以下规则,其中提到了mod_proxy的部分,或者您可能必须放入extra/httpd-ajp.conf

ProxyPass /eshop/ http://example.myeshop.com/
ProxyPassReverse /eshop/ http://example.myeshop.com/

这两行应在httpd.conf文件中取消注释。

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so