2015-02-10 35 views
0

我试图让html5mode工作,并通过将此添加到我的.htaccess文件中,我能够使其工作。使用REST api编写html5mode的.htaccess文件

RewriteEngine On 

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

RewriteRule^index.html [L] 

我叫api.php在同一文件夹作为我的index.html文件将处理后端的REST API的PHP文件。

Basicly我想html5mode继续工作,但到例如本地主机/ API/...发送的所有请求api.php

我试了行,但它打破了html5mode。

如果我能弄清楚这一点,那将会很棒。

致以问候

回答

0

此配置被另一个答案建议。

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]