子文件夹Laravel + htaccess中的角度应用程序

时间:2015-06-09 17:12:31

标签: angularjs apache .htaccess mod-rewrite laravel-5

我有一个laravel 5安装。工作完美。 公用文件夹中的.htaccess是默认的,工作正常:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

public(root)文件夹中,我有一个名为webapp

的文件夹

webapp包含我的应用内置版的网页版angularjs,需要push states

.htaccess文件夹中的理想webapp将是:

<ifModule mod_rewrite.c>
    RewriteEngine On

    RewriteBase /

    # html5 pushstate (history) support:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !index
    RewriteRule (.*) index.html [L]

</ifModule>

但似乎.htaccess文件夹中的webapp未被触发。

我可能需要在laravel public文件夹中编写条件和规则。但我不知道如何处理这个以及以什么顺序等等。

有人可以帮助我将2 .htaccess个文件合并为一个文件放在public文件夹中。

1 个答案:

答案 0 :(得分:0)

这对我有用:

bash-3.2$ cat .htaccess
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301] #This creates a redirect loop for angular

    # IF the resource does not exist as an actual directory...
    RewriteCond %{REQUEST_FILENAME} !-d
    # OR an actual file...
    RewriteCond %{REQUEST_FILENAME} !-f
    # AND is being requested from angular directory a/
    # THEN send it to the angular routing file
    RewriteRule ^(a/.*) /a/index.html [NC,L]

    # IF the resource does not exist as an actual directory...
    RewriteCond %{REQUEST_FILENAME} !-d
    # OR an actual file...
    RewriteCond %{REQUEST_FILENAME} !-f
    # THEN send the traffic to laravel routing
    RewriteRule ^ index.php [L]

</IfModule>
bash-3.2$