Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 使用RESTAPI为HTML5模式编写.htaccess文件_Angularjs_.htaccess_Rest - Fatal编程技术网

Angularjs 使用RESTAPI为HTML5模式编写.htaccess文件

Angularjs 使用RESTAPI为HTML5模式编写.htaccess文件,angularjs,.htaccess,rest,Angularjs,.htaccess,Rest,我正试图让HTML5模式工作,通过将它添加到我的.htaccess文件中,我能够使它工作 RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^ index.html [L] 我的index.html文件与一个名为api.php的php文件位于同一文件夹中,该文件将处理后端RESTAPI 基本上,

我正试图让HTML5模式工作,通过将它添加到我的.htaccess文件中,我能够使它工作

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^ index.html [L]
我的index.html文件与一个名为api.php的php文件位于同一文件夹中,该文件将处理后端RESTAPI

基本上,我希望HTML5模式继续工作,但所有的请求,例如localhost/api/。。。发送到api.php

我尝试了几行,但它打破了HTML5模式

如果我能弄明白这一点,那就太棒了


最诚挚的问候

另一个答案建议使用此配置

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

# otherwise forward it to index.html 
RewriteRule ^.*$ - [NC,L]
RewriteRule ^. /index.html [NC,L]