Reputation: 390
I'm trying to rewrite all URL in my Angular 6 application. I've tried many rules and nothing worked.
.htaacess works, because this rule is working fine:
RewriteRule ^test\.html http://www.google.com/? [R=301,L]
Tried rules:
RewriteEngine On
Options +FollowSymLinks
RewriteBase /
RewriteRule ^#/(.*)$ /$1 [L,R=301]
RewriteRule ^#/(.*)$ $1
RewriteRule ^/#/(.*)$ $1
RewriteRule ^#/(.*)$ /$1 [N]
My urls look like this: www.domain.pl/#/login and I want to rewrite them to www.domain.pl/login
Upvotes: 0
Views: 1130
Reputation: 390
I've resolved this problem with adding this in AppModule Providers:
providers: [{provide: LocationStrategy, useClass: PathLocationStrategy}]
and importing
import { PathLocationStrategy, LocationStrategy } from '@angular/common';
After that I created .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
Now everything works great without # in URLs :)
Upvotes: 3