I have an app running at "www.example.com", which is sitting along side some static html pages. I need to provide a 'registration' link that goes to www.example.com/guest_register. This works locally, but not on the server.
Background:
When I run locally, I can create a link to http://localhost:4200/guest?token=asdf&user=username that works fine to register a new user. Out on the server, a link to http://www.example.com/guest?token=asdf&user=username gives a 404 error....an link to http://www.example.com/#/guest?token=asdf&user=username sends me to my index.html. I tried adding the '#' on a hunch, but I'm not sure what the real difference is.
The public_html directory of the server looks like:
index.html //a static page main.html // my actual Angular app styles.-----.js scripts.-----.js runtime.----.js polyfills.----.js main.-----.js 3rdpartylicenses.txt assets/
I serve up index.html for the general public, and then link into main.html as needed to log in registered users. Locally, the browser address bar switches from file://..index.html to localhost:4200 when I link into my app. On the server, the address bar reloads from www.example.com to www.example.com.
Here is my route map in app.module.ts:
const appRoutes: Routes = [
{ path: '', component: WizardComponent, canActivate: [AuthGuard] },
{ path: 'login', component: LoginComponent },
{ path: 'guest', component: GuestComponent },
{ path: 'admin', component: AdminComponent, canActivate: [AdminGuard] },
{ path: '**', redirectTo: '' }
];
.
.
@NgModule({
declarations: [
.
.
],
imports: [
BrowserModule,
BrowserAnimationsModule,
HttpClientModule,
RouterModule.forRoot(appRoutes),
.
.
Nothing too fancy. So, what is keeping me from directly appending /guest to the end of the URL while on the server, but not locally?
EDIT: It seems my app is falling back to index.html when it should be falling back to main.html (my angular app) when an unrecognized URL is requested, according to these official docs:
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
My .htaccess already has a few mysterious lines in it that I only understand well enough to know they work to redirect all users other than my IP to maintenance.html when maintenance.enable exists:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^MY\.IP\.ADD\.RESS
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{DOCUMENT_ROOT}/maintenance.enable -f
RewriteCond %{REQUEST_URI} !^/maintenance\.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
#RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^(.*)$ /maintenance.html [R=302,L]
</IfModule>
How do I integrate the suggestion on the official docs into my existing .htaccess file?