gpt4 book ai didi

angularjs - 单页应用程序的 vhosts conf

转载 作者:行者123 更新时间:2023-12-04 09:03:16 26 4
gpt4 key购买 nike

我有一个 angular 应用程序,我在本地使用 apache 提供服务。我的 vhosts.conf 是:

<VirtualHost *:80>
ServerName my.app.com
DirectoryIndex index.html
DocumentRoot /export/www/app
<Directory "/export/www/app">
order allow,deny
allow from all

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.html/$1 [L]
</Directory>
</VirtualHost>

如果我转到应用程序的根目录,则一切正常。我在应用程序中进行了一些导航,将我带到了 my.app.com/some/location,但仍然没有问题。

但是,如果此时我重新加载页面,则会出现 404 错误。为了回到我想要的点,我需要回到根目录并再次通过应用程序导航,或者通过 url my.app.com/#/some/location 进行搜索

有什么我可以用重写规则做的事情,这样我就不需要散列来重新加载路由吗?我尝试将现有规则编辑为:
RewriteRule ^(.*)$ index.html/#/$1 [L]

任何想法都非常感谢
C

最佳答案

问题是我使用的是较新版本的 apache,其中配置规则已更改。我更新的虚拟主机现在读取

<VirtualHost *:80>
ServerName my.app.com
DirectoryIndex index.html
DocumentRoot /export/www/app
<Directory "/export/www/app">
order allow,deny
allow from all

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]
</Directory>
</VirtualHost>

关于angularjs - 单页应用程序的 vhosts conf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31744657/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com