我想设置使用Apache的多个redirect,但完全难住,如何做到这一点?
我有一个nodejs实例,它提供了我的主页上运行我的服务器上端口4000.它可以从服务器访问本地主机:4000(端口4000不对外部访问)。
我有一个WordPress的实例的博客。
该博客驻留在mysite.com/blog
所以。 我希望mysite.com/blog/xxxxx的所有请求都被redirect到wordpress实例,并将所有其他请求(例如mysite.com/xxxx/yyyy)redirect到我的节点实例http:// localhost:4000 / XXXXX / YYYY
我的configuration文件看起来像这样
9 <VirtualHost *:80> 10 11 # Admin email, Server Name (domain name) and any aliases 12 ServerAdmin xxxxx 13 ServerName xxxxx 14 ServerAlias xxxxx 15 16 17 # Index file and Document Root (where the public files are located) 18 DirectoryIndex index.html index.php 19 DocumentRoot /xxx/xxx/public_html/xxx/public
…..
26 <Location /> ?? What goes here? 31 </Location>
……
33 <Location /blog> 34 RewriteEngine On 35 RewriteBase /blog/ 36 RewriteRule ^index\.php$ - [L] 37 RewriteCond %{REQUEST_FILENAME} !-f 38 RewriteCond %{REQUEST_FILENAME} !-d 39 RewriteRule . /blog/index.php [L] 40 </Location>
我曾尝试设置重写规则和代理,但博客不工作,或主页不起作用。
我相信(虽然我可能会误)Apache的进程依次处理<Location>标签,所以如果你想映射/博客的子文件夹,你需要做
<Location /blog> RewriteEngine On RewriteBase /blog/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /blog/index.php [L] </Location> ProxyPass / http://localhost:4000/ ProxyPassReverse / http://localhost:4000/
尝试在您的<Location /blog>...</Location>部分放置以下几行:
ProxyPass / http://localhost:4000/ ProxyPassReverse / http://localhost:4000/
我不太清楚位置和代理指令之间的匹配是如何工作的。 但是,当涉及到代理指令时,他们只能按照有序的,首先匹配的原则工作。