将角度和laravel放在同一个根文件夹下(.htaccess)

时间:2017-06-01 11:48:15

标签: laravel .htaccess angular angular-routing

我有这个文件夹结构

--laravel
----public
------index.php
------uploads
--------image.jpg
--angular
----dist
------index.html

我想要3件事

1)http(s)//www.domain.com/public/uploads/image.jpg转到laravel-> public-> uploads-> image.jpg

2)http(s)//www.domain.com/api/test转到laravel-> public-> index.php

3)http(s)://www.domain.com/every_other_url转到angular-> dist

我已创建此.htacces文件

DirectoryIndex index.html index.htm default.htm index.php index.php3 index.phtml index.php5 index.shtml mwindex.phtml
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^api/(.*)$ laravel/public/$1 [L]
    RewriteRule ^public/(.*)$ laravel/public/$1 [L]
    RewriteCond %{REQUEST_URI} !^/angular/dist/
    RewriteRule ^(.*)$ /angular/dist/$1
</IfModule>

第一和第二项要求正常运作。现在我需要修复第3个

(我没有使用HashLocationStrategy)

1 个答案:

答案 0 :(得分:2)

DirectoryIndex /angular/dist/index.html    
<IfModule mod_rewrite.c>
RewriteEngine on

RewriteRule ^api/(.*)$ laravel/public/$1 [L]
RewriteRule ^public/(.*)$ laravel/public/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.(.*) /angular/dist/$1.$2 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /angular/dist/index.html [NC,L]

</IfModule>