问题
Morning;
I am trying to deploy my angular project under apache and I encountered some problems with redirection in Angular.
The user try to authenticate in my App using Oauth2. So it will be redirect to another domain to make authentication and then the other domain redirect the user to my application with an access token. The problem when making redirection, it shows up “resource not found”, so I tried to find a solution and I found those two solution:
I insert the “{usehash : true}” in RootModule.forRoot() but it did not works
/ 20180103143205
// http://radouani-**********?username=*****&scope=token%20openid%20profile&client_id=***&redirect_uri=http%3A%****en&response_type=token
{
"ErrorCode": "invalid_request",
"Error": "Invalid redirection uri http://******/#/authentication/token"
}
I add this configuration under apache
Apache Config :
<VirtualHost *:80>
ServerName www.ofi-demo.com
ServerAlias ofi-demo.com
DocumentRoot /var/www/demo/public_html
<Directory /var/www/demo/public_html>
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]
</Directory>
</VirtualHost>
but I got this problem “"Uncaught SyntaxError: Unexpected token <" . I looked in the network tab under chrome and I found that apache (I think) insert those line in js file
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>OFI-Asset Management API DEMO</title><base href="./"><link rel="icon" type="image/x-icon" href="favicon.ico"><link href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css" rel="stylesheet"><link href="assets/fonts/feather/style.min.css" rel="stylesheet"><link href="assets/fonts/simple-line-icons/style.css" rel="stylesheet"><link href="https://fonts.googleapis.com/css?family=Rubik:300,400,500,700,900|Montserrat:300,400,500,600,700,800,900" rel="stylesheet" type="text/css"><link rel="stylesheet" href="assets/vendor/pace/themes/black/pace-theme-flash.css"/><style type="text/css">.pace .pace-activity {
top: 19px;
……
}
So what configuration I need to make the redirection works in Angular?
回答1:
Thanks I add this configuration in .htaccess file (in the same directory where the index.html resides) and it works; Thanks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
来源:https://stackoverflow.com/questions/48076301/apache-angular-oauth-redirection-resource-not-found