在Apache中为其他端口重写规则

Nik*_*ahu 5 apache .htaccess mod-rewrite spring url-rewriting

我的Apache(Tomcat)-Spring服务器在端口8080上运行。我想调用localhost默认端口(80),并希望重定向到端口8080。

我启用了mod-rewrite,DigitalOcean的以下规则可以正常工作。

RewriteRule ^orange.html$ apple.html
Run Code Online (Sandbox Code Playgroud)

我从Apache URL重写文档中读取了Apache的重写规则

但是,以下规则不起作用:

RewriteEngine On    # Turn on the rewriting engine
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http://localhost:8080/$1 [L,R]
Run Code Online (Sandbox Code Playgroud)

我的意图是允许跨域支持而不在spring控制器中启用CORS。(这是一个硬规则)

.htaccess位于/ var / www / html中。另外我不希望其他请求在端口8080上重定向,除了本地主机/(my_specified_string)上的请求

Nik*_*ahu 5

ProxyPass是这里需要的,而不是重写引擎。

在下面的配置线000-default.conf目前在/etc/apache2/sites-available做的伎俩。

ProxyPass /servlet-name http://localhost:8080/servlet-name
ProxyPassReverse /servlet-name http://localhost:8080/servlet-name
Run Code Online (Sandbox Code Playgroud)

这将对的任何请求/servlet-name重新定向http://localhost:8080/servlet-name

可以将上面的“ servlet-name”替换为其各自的servlet名称。

此处的更多信息:http : //httpd.apache.org/docs/2.2/mod/mod_proxy.html