2016-05-11 24 views
0

Ich verwende apache als http Server, tomcat8 als Anwendungsserver (rest) und express als angular2 statischen Server.Apache Rewrite-Regel für html5 pushstate mit Proxy und Ausschlüsse

Es folgt mein virtuellen Host Element

<VirtualHost *:80> 
    ... other things - name path and logs ... 


    ProxyPass /rest/ http://localhost:8080/rest/ 
    ProxyPassReverse /rest/ http://localhost:8080/rest/ 

    ProxyPass/http://localhost:3000/ 
    ProxyPassReverse/http://localhost:3000/ 

</VirtualHost> 

Im Grunde, was ich tue, ist tue, wenn jemand http://localhost trifft er statische Web-App sehen sollte, die auf http://localhost:3000 und wenn jemand (Web-Anwendung) gehostet wird, stellen Antrag auf http://localhost/rest , Anfrage sollte tomcat8 auf 8080 für Rest Anruf erreichen.

Dies funktioniert ordnungsgemäß.

Nun, was ich will

I express statische Server verwenden die angular2 Anwendung dient. Diese Anwendung verwendet html5pushState als Router. Wenn der Benutzer die Seite aktualisiert, wird der Fehler nicht gefunden angezeigt.

möchte ich Umleitungsregel, die

folgend umleiten

http://localhost/somepath =>http://localhost?redirect=/somepath

http://localhost/rest => (umschreiben nicht, aber gehen Sie zu Proxy) http://localhost:8080/rest

ich nicht bekommen, wie Rewrite-Regel zu verwenden, Hier.

RewriteEngine on 
RewriteCond %{REQUEST_URI} !(/rest/) 
RewriteCond "%{QUERY_STRING}" "!(.*(?:^|&))_redirect=([^&]*)&?(.*)&?$" 
RewriteRule "^/?(.*)"  "http://localhost?_redirect=$1" [L,R,NE,QSA] 

Oben ist mein Code für das gleiche, aber es funktioniert nicht. Kann mir jemand einen guten Zustand und eine richtige Regel vorschlagen?

Antwort

0

Dies ist, was ich am Ende tun

RewriteEngine on 
    // exception for everything which is on the webapp but has physical path 
    RewriteCond %{REQUEST_URI} !(/rest/) 
    RewriteCond %{REQUEST_URI} !(/bootstrap-template/) 
    RewriteCond %{REQUEST_URI} !(/lib/) 
    RewriteCond %{REQUEST_URI} !(/app/) 
    RewriteCond %{REQUEST_URI} !(/assets/) 
    RewriteCond %{REQUEST_URI} !(/browser-sync/)  
    RewriteCond %{REQUEST_URI} !(/node_modules/)  
    RewriteCond %{REQUEST_URI} !(/styles.css)$ 
    RewriteCond %{REQUEST_URI} !(/Helvetica.otf)$ 
    // exceptions end 

    RewriteCond %{REQUEST_URI} (/)(.+)$ 
    RewriteCond "%{QUERY_STRING}" "!(.*(?:^|&))_redirect=([^&]*)&?(.*)&?$" 
    RewriteRule "^/(.*)"  "http://localhost?_redirect=$1" [L,R,NE,QSA] 

    ProxyPass /pixie/ http://localhost:8080/pixie/ 
    ProxyPassReverse /pixie/ http://localhost:8080/pixie/ 

    ProxyPass/http://localhost:3000/ 
    ProxyPassReverse/http://localhost:3000/