Угловой 2 apache .htaccess файл 404 на подстраницах

Я успешно установил и запустил приложение Angular 2 на своем сервере Apache, я могу перемещаться по страницам с помощью [routerLink]="['/register']"

Однако, когда я обновляю страницу, я получаю сообщение об ошибке 404 на странице регистрации. Что-то не так с моими правилами переписывания:

Options +FollowSymLinks
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]
</ifModule>

Также вот мой apache VirtualHost

<VirtualHost *:80>
ServerName example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/front/dist/browser
<Directory /var/www/html/front>
AllowOverride All
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

5

Решение

Да, насколько я понимаю, ваши правила переписывания не кажутся мне правильными ..

Вы говорите, если запрошенный документ не является файлом А ТАКЖЕ не каталог А ТАКЖЕ Я думаю, что не страница индекса, а затем перенаправить на index.html а что если они есть ?? И почему вы не хотите перейти на страницу индекса? я верю RewriteCond %{REQUEST_URI} !index означает, что вы не хотите идти в индекс.

Я не знаю, каково ваше требование, но для упрощенного требования я использую:

    RewriteCond %{REQUEST_FILENAME} -s [OR]   # don't redirect for files which phycically exit
RewriteCond %{REQUEST_FILENAME} -d  # don't redirect for directories
RewriteRule ^.*$ - [NC,L]  # if the above condition(s) satisfy then do nothing
RewriteRule ^.*$ index.html [NC,L] # for everything else, redirect to index.html
0

Другие решения

Попробуй это

RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]

# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html

Проверь это:https://github.com/angular/angular-cli/issues/1630

Ref:https://ngmilk.rocks/2015/03/09/angularjs-html5-mode-or-pretty-urls-on-apache-using-htaccess/

0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector