2016-05-11 1 views
0

J'utilise apache comme http serveur, tomcat8 comme serveur d'applications (rest) et express comme angular2 serveur statique.Apache règle de réécriture pour html5 pushState avec procuration et exclusions

Ce qui suit est mon élément hôte virtuel

<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> 

En fait ce que je fais est, chaque fois que quelqu'un frappe http://localhost il devrait voir l'application web statique qui est hébergé sur http://localhost:3000 et quand quelqu'un (application web) faire une demande pour http://localhost/rest , demande doit atteindre tomcat8 sur 8080 pour appel de repos.

Cela fonctionne correctement.

Maintenant ce que je veux

J'utilise express serveur statique qui sert l'application angular2. Cette application utilise html5pushState comme routeur. Chaque fois que l'utilisateur actualise la page, il affiche une erreur introuvable.

Je veux règle de redirection qui redirigent comme suit

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

http://localhost/rest => (ne pas réécrire mais passez à proxy) http://localhost:8080/rest

Je ne reçois pas comment utiliser la règle de réécriture ici.

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

Ci-dessus est mon code pour le même, mais il ne fonctionne pas. Quelqu'un peut-il me suggérer la bonne condition et la règle?

Répondre

0

C'est ce que je finis par faire

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/