.htaccess Wordpress 和 NodeJS 运行 一起
.htaccess Wordpress and NodeJS running alongside
我正在尝试在一个旧的 Wordpress 网站旁边添加一个为 NodeJS 实例提供服务的路由。
问题是我想 运行 Wordpress 和 Node.js 在同一台服务器上但在不同的路由上。
Wordpress 运行宁在这里 http://example.com
节点运行宁在这里http://example.com:61000/oferta-de-pret-traduceri
.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/oferta-de-pret-traduceri$ http://127.0.0.1:61000/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/oferta-de-pret-traduceri/(.*)$ http://127.0.0.1:61000/ [P,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
我不太了解 Wordpress,也不太了解 .htaccess,除非迫不得已,否则我不想将所有内容都迁移到 NGINX。
我希望我的 Node.js 实例在 http://example.com/oferta-de-pret-traducerii
上 运行 而不是 http://example.com:61000
。
如果我尝试访问 http://example.com/oferta-de-pret-traduceri
,Wordpress 也会抛出 404 错误
希望有人遇到过这种情况,并且有一个简单的解决办法。
非常感谢您!
ProxyPassMatch
https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypassmatch
你可能会过得更好
ProxyPassMatch "^/oferta-de-pret-traduceri$" "http://127.0.0.1:61000/"
mod_rewrite 的文档是这样说的:
Consider using either ProxyPass or ProxyPassMatch whenever possible in
preference to mod_rewrite.
如果您不能使用 ProxyPass,试试这个规则:
RewriteRule ^oferta-de-pret-traduceri http://127.0.0.1:61000 [P,L]
我用这个工具来测试:http://htaccess.mwl.be/
如果您的节点应用程序希望 'oferta-de-pret-traduceri' 在 URL 中,您将需要此规则:
RewriteRule ^oferta-de-pret-traduceri http://127.0.0.1:61000/oferta-de-pret-traduceri [P,L]
我正在尝试在一个旧的 Wordpress 网站旁边添加一个为 NodeJS 实例提供服务的路由。 问题是我想 运行 Wordpress 和 Node.js 在同一台服务器上但在不同的路由上。
Wordpress 运行宁在这里 http://example.com
节点运行宁在这里http://example.com:61000/oferta-de-pret-traduceri
.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/oferta-de-pret-traduceri$ http://127.0.0.1:61000/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/oferta-de-pret-traduceri/(.*)$ http://127.0.0.1:61000/ [P,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
我不太了解 Wordpress,也不太了解 .htaccess,除非迫不得已,否则我不想将所有内容都迁移到 NGINX。
我希望我的 Node.js 实例在 http://example.com/oferta-de-pret-traducerii
上 运行 而不是 http://example.com:61000
。
如果我尝试访问 http://example.com/oferta-de-pret-traduceri
希望有人遇到过这种情况,并且有一个简单的解决办法。
非常感谢您!
ProxyPassMatch
https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypassmatch
ProxyPassMatch "^/oferta-de-pret-traduceri$" "http://127.0.0.1:61000/"
mod_rewrite 的文档是这样说的:
Consider using either ProxyPass or ProxyPassMatch whenever possible in preference to mod_rewrite.
如果您不能使用 ProxyPass,试试这个规则:
RewriteRule ^oferta-de-pret-traduceri http://127.0.0.1:61000 [P,L]
我用这个工具来测试:http://htaccess.mwl.be/
如果您的节点应用程序希望 'oferta-de-pret-traduceri' 在 URL 中,您将需要此规则:
RewriteRule ^oferta-de-pret-traduceri http://127.0.0.1:61000/oferta-de-pret-traduceri [P,L]