2015-02-10 36 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]