Apache 구성에서 모든 요청을 index.html로 리디렉션하려는 모든 시도가 실패합니다.

Apache 구성에서 모든 요청을 index.html로 리디렉션하려는 모든 시도가 실패합니다.

index.html만 요청해야 하는 Angular SPA가 있습니다. 이 서버에 대한 다른 모든 URL 요청은 SPA에서 내부적으로 처리됩니다. 모든 404 오류를 index.html로 리디렉션하고 싶습니다.

[업데이트: 이 게시물에서는 이를 달성하기 위해 mod_rewrite를 사용하는 방법을 설명합니다. 어쩌면 이건 내가 해야 할 일이 아닐 수도 있다. ]

저는 Apache 구성을 처음 사용합니다. 온라인에서 찾은 모든 솔루션은 실패했습니다. http 트래픽을 https로 리디렉션하는 재작성을 성공적으로 추가할 수 있었습니다. 그래서 mod_rewrite를 올바르게 설정해야 한다고 생각합니다. 그러나 다시 작성하려는 다른 모든 시도는 실패했습니다. 나는 명백한 초보자 실수를 저질렀을 수도 있습니다.

실행 중: 서버 버전: Apache/2.4.41 (Ubuntu) 서버 빌드: 2021-10-14T16:24:43

구성 파일을 편집한 후에는 항상 "sudo systemctl reload apache2.1"을 실행합니다.

이것은 내 가상 호스트 govmeeting.org.conf의 구성 파일입니다.

<Directory /var/www/html>
        Require all granted
</Directory>
<VirtualHost *:80>
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

</VirtualHost>

업데이트: 로깅을 설정했습니다.

LogLevel trace6 rewrite_module:trace6

이 리디렉션만 갖도록 구성을 편집했습니다.

RewriteEngine on
RewriteRule ^home.html$ index.html [NC]

그런 다음 브라우저에서 "govmeeting.org/dashboard", ".../xxx.txt" 및 ".../home.html"로 요청을 보냈습니다.

이것은 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 "-" "-"

error.log의 꼬리입니다. 이 결과를 어떻게 해석해야 할지 모르겠습니다. 내 웹사이트 폴더의 콘텐츠에는 index.html과 javascript 파일 세트만 포함되어 있습니다. ("robots.txt" 등은 없습니다). 이러한 요청을 다시 작성하려고 합니까?

[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

관련 정보