【问题标题】:Put angular and laravel under the same root folder (.htaccess)将 angular 和 laravel 放在同一个根文件夹下(.htaccess)
【发布时间】:2017-11-02 13:15:37
【问题描述】:

我有这个文件夹结构

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

我想要三样东西

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>

第一个和第二个要求正常工作。现在我需要修复第三个

(我没有使用 HashLocationStrategy)

【问题讨论】:

    标签: laravel .htaccess angular angular-routing


    【解决方案1】:
    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>
    

    【讨论】:

    • RewriteRule ^api/(.*)$ laravel/public/$1 [L] RewriteRule ^public/(.*)$ laravel/public/$1 [L] 以上规则无效。它正在重定向到角度路由策略而不是 laravel
    猜你喜欢
    • 2019-10-16
    • 1970-01-01
    • 2020-02-10
    • 2012-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-29
    • 1970-01-01
    相关资源
    最近更新 更多