Sample Header Ad - 728x90

In Apache config all my attempts to redirect all requests to index.html fail

0 votes
0 answers
864 views
I have an Angular SPA that should only request index.html. All other URL requests to this server are handled internally by the SPA. I want to redirect all 404 errs to index.html. [UPDATE: This post describes how I am trying to use mod_rewrite for this. Perhaps this is not what I should be doing.] I am new to Apache configuration. Every solution that I found online for this fails. I was able to successfully add a re-write to redirect http traffic to https. So I assume that mod_rewrite should be set up correctly. But all my other attempts at a re-write fail. I am probably making some obvious newbee mistake. I am runing: Server version: Apache/2.4.41 (Ubuntu) Server built: 2021-10-14T16:24:43 After editing the config file, I always run "sudo systemctl reload apache2. Here is my config file for my virtual host, govmeeting.org.conf: Require all granted ServerName govmeeting.org ServerAlias www.govmeeting.org ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # This re-directs http traffic to https. This works. RewriteEngine on RewriteCond %{SERVER_NAME} =govmeeting.org [OR] RewriteCond %{SERVER_NAME} =www.govmeeting.org RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] # This was one solution I found to redirect all 404 errs to the main domain. # It does NOT work. I still get 404 errs for govmeeting.org/somepage. # ErrorDocument 404 https://govmeeting.org/ # This is another solution that I found that does NOT work: # RewriteCond %{REQUEST_FILENAME} !-f # RewriteCond %{REQUEST_FILENAME} !-d # RewriteRule . /index.html [L] # # Here is another suggestion that does NOT work: # RewriteBase / # RewriteRule ^index\.html$ - [L] # RewriteCond %{REQUEST_FILENAME} !-f # RewriteCond %{REQUEST_FILENAME} !-d # RewriteRule . /index.html [L] # # In this, I tried to redirect "somepage" to index.html. Does NOT work. # I tried with and without a second "RewriteEngine on", because the # suggestion was using it twice. # RewriteEngine on # RewriteRule ^somepage$ index.html [NC] # # Here I added "/" before each file name. Does NOT work. # RewriteEngine on # Redirect /x.html /index.html UPDATE: I set up logging with: LogLevel trace6 rewrite_module:trace6 I edited my config to only have this redirect: RewriteEngine on RewriteRule ^home.html$ index.html [NC] I then sent requests from the browser for "govmeeting.org/dashboard", ".../xxx.txt" and ".../home.html". Here is a tail of access.log: 114.119.156.56 - - [04/Dec/2021:02:03:03 +0000] "GET /robots.txt HTTP/1.1" 404 493 "-" "Mozilla/5.0 (compatible;PetalBot;+https://webmaster.petalsearch.com/site/petalbot) " 67.80.142.21 - - [04/Dec/2021:02:07:48 +0000] "GET /dashboard HTTP/1.1" 404 5729 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36" 67.80.142.21 - - [04/Dec/2021:02:08:08 +0000] "-" 408 5213 "-" "-" 188.166.170.135 - - [04/Dec/2021:02:12:50 +0000] "GET /currentsetting.htm HTTP/1.1" 404 5607 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36" 188.166.170.135 - - [04/Dec/2021:02:12:50 +0000] "GET / HTTP/1.0" 400 624 "-" "-" 67.80.142.21 - - [04/Dec/2021:02:19:58 +0000] "GET /xxx.txt HTTP/1.1" 404 5729 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36" 67.80.142.21 - - [04/Dec/2021:02:20:18 +0000] "-" 408 5213 "-" "-" 67.80.142.21 - - [04/Dec/2021:02:25:06 +0000] "GET /home.html HTTP/1.1" 404 5729 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36" 67.80.142.21 - - [04/Dec/2021:02:25:26 +0000] "-" 408 5213 "-" "-" Here is a tail of error.log. I am not sure how to interpret these results. The contents of the folder for my site only contains an index.html and a group of javascript files. (no "robots.txt", etc). Is it attempting to do a rewrite for these requests? [Sat Dec 04 02:03:03.013635 2021] [rewrite:trace2] [pid 4283] mod_rewrite.c(483): [client 114.119.156.56:18482] 114.119.156.56 - - [govmeeting.org/sid#7f337385b810][rid#7f337391a0a0/initial] init rewrite engine with requested uri /robots.txt [Sat Dec 04 02:03:03.013654 2021] [rewrite:trace3] [pid 4283] mod_rewrite.c(483): [client 114.119.156.56:18482] 114.119.156.56 - - [govmeeting.org/sid#7f337385b810][rid#7f337391a0a0/initial] applying pattern '/^home.html$' to uri '/robots.txt' [Sat Dec 04 02:03:03.013702 2021] [rewrite:trace1] [pid 4283] mod_rewrite.c(483): [client 114.119.156.56:18482] 114.119.156.56 - - [govmeeting.org/sid#7f337385b810][rid#7f337391a0a0/initial] pass through /robots.txt [Sat Dec 04 02:28:32.122092 2021] [rewrite:trace2] [pid 4566] mod_rewrite.c(483): [client 167.248.133.59:50802] 167.248.133.59 - - [35.211.93.45/sid#7fd23b007810][rid#7fd23ca000a0/initial] init rewrite engine with requested uri / [Sat Dec 04 02:28:32.122099 2021] [rewrite:trace3] [pid 4566] mod_rewrite.c(483): [client 167.248.133.59:50802] 167.248.133.59 - - [35.211.93.45/sid#7fd23b007810][rid#7fd23ca000a0/initial] applying pattern '^home.html$' to uri '/' [Sat Dec 04 02:28:32.122175 2021] [rewrite:trace1] [pid 4566] mod_rewrite.c(483): [client 167.248.133.59:50802] 167.248.133.59 - - [35.211.93.45/sid#7fd23b007810][rid#7fd23ca000a0/initial] pass through / [Sat Dec 04 02:28:32.122306 2021] [rewrite:trace2] [pid 4566] mod_rewrite.c(483): [client 167.248.133.59:50802] 167.248.133.59 - - [35.211.93.45/sid#7fd23b007810][rid#7fd23b1090a0/subreq] init rewrite engine with requested uri /index.html [Sat Dec 04 02:28:32.122311 2021] [rewrite:trace3] [pid 4566] mod_rewrite.c(483): [client 167.248.133.59:50802] 167.248.133.59 - - [35.211.93.45/sid#7fd23b007810][rid#7fd23b1090a0/subreq] applying pattern '^home.html$' to uri '/index.html' [Sat Dec 04 02:28:32.122316 2021] [rewrite:trace1] [pid 4566] mod_rewrite.c(483): [client 167.248.133.59:50802] 167.248.133.59 - - [35.211.93.45/sid#7fd23b007810][rid#7fd23b1090a0/subreq] pass through /index.html [Sat Dec 04 02:28:32.195319 2021] [rewrite:trace2] [pid 4567] mod_rewrite.c(483): [client 167.248.133.59:40432] 167.248.133.59 - - [35.211.93.45/sid#7fd23b007810][rid#7fd23ca000a0/initial] init rewrite engine with requested uri / [Sat Dec 04 02:28:32.195325 2021] [rewrite:trace3] [pid 4567] mod_rewrite.c(483): [client 167.248.133.59:40432] 167.248.133.59 - - [35.211.93.45/sid#7fd23b007810][rid#7fd23ca000a0/initial] applying pattern '^home.html$' to uri '/' [Sat Dec 04 02:28:32.195342 2021] [rewrite:trace1] [pid 4567] mod_rewrite.c(483): [client 167.248.133.59:40432] 167.248.133.59 - - [35.211.93.45/sid#7fd23b007810][rid#7fd23ca000a0/initial] pass through / [Sat Dec 04 02:28:32.195467 2021] [rewrite:trace2] [pid 4567] mod_rewrite.c(483): [client 167.248.133.59:40432] 167.248.133.59 - - [35.211.93.45/sid#7fd23b007810][rid#7fd23b1090a0/subreq] init rewrite engine with requested uri /index.html [Sat Dec 04 02:28:32.195472 2021] [rewrite:trace3] [pid 4567] mod_rewrite.c(483): [client 167.248.133.59:40432] 167.248.133.59 - - [35.211.93.45/sid#7fd23b007810][rid#7fd23b1090a0/subreq] applying pattern '^home.html$' to uri '/index.html' [Sat Dec 04 02:28:32.195476 2021] [rewrite:trace1] [pid 4567] mod_rewrite.c(483): [client 167.248.133.59:40432] 167.248.133.59 - - [35.211.93.45/sid#7fd23b007810][rid#7fd23b1090a0/subreq] pass through /index.html
Asked by John Pankowicz (1429 rep)
Dec 2, 2021, 03:55 PM
Last activity: Dec 4, 2021, 09:35 PM