.htaccess apache上的Angular 布线返回文件未找到

j0pj023g  于 2022-11-16  发布在  Apache
关注(0)|答案(1)|浏览(133)

我使用PathLocationStrategy并在apache上部署了我的angular 14应用程序。我的angular 14应用程序文件在文件夹“test”中,它在文件夹“public_html”中。
因此文件夹路径如下所示:/var/www/游戏站点/公共html/测试
我已经更改了“public_html”中的.htaccess文件,但仍然显示“未找到文件”。
我的基本引用如下所示:

<base href="/teste/">

重写.htaccess文件中规则

RewriteEngine On
  # If an existing asset or directory is requested go to it as it is 
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
  RewriteRule ^ - [L]
  # If the requested resource doesn't exist, use index.html
RewriteRule ^/index.html

请问我做错了什么?我猜也许重写规则是错误的?
我已尝试更新重写规则并更改为useHash,但没有效果

qoefvg9y

qoefvg9y1#

RewriteRule ^/index.html

RewriteRule参数之间缺少一个 * 空格 *。
但是,如果您的所有文件都在/test子目录中(包括index.html),并且/test出现在URL中,那么.htaccess文件也应该在/test子目录中,而不是文档根目录中。

# /test/.htaccess

DirectoryIndex index.html

RewriteEngine On

RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]

请注意,在RewriteRule * 替换 * 中,index.html之前没有斜线。
相对替换字符串相对于包含.htaccess文件的目录。同样,与RewriteRule * 模式 * 匹配的URL路径也相对于包含.htaccess文件的目录。
第一个规则只是一个优化,没有它也能工作。

相关问题