rewrite rules for apache 2 to use with angular js

前端 未结 5 1934
长情又很酷
长情又很酷 2020-12-02 23:23

Obviously, there are a lot of mod rewrite discussions and answers all across the web. However, I am having a hard time grasping them. So I thought I would ask here.

5条回答
  •  忘掉有多难
    2020-12-03 00:17

    Here's something to get you going (put this inside your /.htaccess file):

    Options +FollowSymLinks
    IndexIgnore */*
    RewriteEngine on
    
    # if a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteCond %{REQUEST_URI} !/api
    
    # otherwise forward it to index.html 
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^app/. /app/index.html [NC,L]
    

    NOTE: For newer Apache versions see also the next answer, which uses the much easier FallbackResource

提交回复
热议问题