Apache - 사용자 브라우저에서 URL을 변경하지 않고 리디렉션

Apache - 사용자 브라우저에서 URL을 변경하지 않고 리디렉션

사용자 브라우저에서 URL을 변경하지 않고 mod_rewrite로 리디렉션하는 방법이 있습니까?

[P]끝에 를 사용하는 솔루션을 보았지만 RewriteRule이것이 효과가 없습니다.

내가 원하는 것:

https://my-server.com/propostas/billy.joe
   < ---> internally redirect to
https://my-server.com/subdir/propostas_usuarios/billy.joe

내가 가진 것:

  <LocationMatch "/propostas/(?<username>[^/]+)">
  RewriteEngine On
  RewriteRule ^/([^/]+)(.*) /subdir/propostas_usuarios/%{env:MATCH_USERNAME}
  </LocationMatch>

이것이 현재 작업중인 것입니다. 하지만 리디렉션 후에는 /subdir/propostas_usuarios새 URL에서 볼 수 있습니다 .

나는 다음과 같이 사용하려고했습니다 [P]:

  RewriteRule (.*) https://%{SERVER_NAME}/hpe/propostas_usuarios/%{env:MATCH_USERNAME} [P]

하지만 이로 인해 다음과 같은 오류가 발생합니다.

[Fri Dec 11 16:02:57.945091 2020] [proxy:debug] [pid 16725:tid 140351293593344] mod_proxy.c(1253): [client 10.0.105.36:52700] AH01143: Running scheme https handler (attempt 0)
[Fri Dec 11 16:02:57.945102 2020] [proxy_ajp:debug] [pid 16725:tid 140351293593344] mod_proxy_ajp.c(744): [client 10.0.105.36:52700] AH00894: declining URL https://my-server.com/subdir/propostas_usuarios/billy.joe
[Fri Dec 11 16:02:57.945124 2020] [proxy_fcgi:debug] [pid 16725:tid 140351293593344] mod_proxy_fcgi.c(1032): [client 10.0.105.36:52700] AH01076: url: https://my-server.com/subdir/propostas_usuarios/billy.joe proxyname: (null) proxyport: 0
[Fri Dec 11 16:02:57.945131 2020] [proxy_fcgi:debug] [pid 16725:tid 140351293593344] mod_proxy_fcgi.c(1035): [client 10.0.105.36:52700] AH01077: declining URL https://my-server.com/subdir/propostas_usuarios/billy.joe
[Fri Dec 11 16:02:57.945149 2020] [proxy:debug] [pid 16725:tid 140351293593344] proxy_util.c(2338): AH00942: HTTPS: has acquired connection for (*)
[Fri Dec 11 16:02:57.945159 2020] [proxy:debug] [pid 16725:tid 140351293593344] proxy_util.c(2393): [client 10.0.105.36:52700] AH00944: connecting https://my-server.com/subdir/propostas_usuarios/billy.joe to my-server.com:443
[Fri Dec 11 16:02:57.946130 2020] [proxy:debug] [pid 16725:tid 140351293593344] proxy_util.c(2616): [client 10.0.105.36:52700] AH00947: connected /subdir/propostas_usuarios/billy.joe to my-server.com:443
[Fri Dec 11 16:02:57.946210 2020] [proxy:debug] [pid 16725:tid 140351293593344] proxy_util.c(3085): AH02824: HTTPS: connection established with 10.30.6.52:443 (*)
[Fri Dec 11 16:02:57.946233 2020] [proxy:error] [pid 16725:tid 140351293593344] AH00961: HTTPS: failed to enable ssl support for 10.30.6.52:443 (my-server.com)
[Fri Dec 11 16:02:57.946236 2020] [proxy:debug] [pid 16725:tid 140351293593344] proxy_util.c(2353): AH00943: HTTPS: has released connection for (*)

어떤 아이디어가 있나요?

답변1

플래그 P는 mod_proxy를 통해 요청을 보냅니다. 여기서는 필요하지 않은 것 같습니다. 다른 하위 디렉터리에 내부적으로 다시 쓰기만 하면 됩니다.

<LocationMatch "/propostas/(?<username>[^/]+)">
RewriteEngine On
RewriteRule ^/([^/]+)(.*) /subdir/propostas_usuarios/%{env:MATCH_USERNAME}
</LocationMatch>

이것은 작동할 것 같습니다. 관찰하고 있는 것처럼 여기에는 외부 리디렉션이 없습니다. 그러나 지시문에는 L(oe END) 플래그 가 없으므로 RewriteRule처리가 계속되고 리디렉션을 트리거하는 이후 지시문일 수 있습니다. (외부 리디렉션은 실제로는~ 전에모든 내부 재작성.)

.htaccess파일(또는 컨테이너) 도 있는 경우 <Directory>이러한 지시어도 나중에 처리되어 잠재적으로 리디렉션을 트리거할 수 있습니다. (?)

<LocationMatch>이 규칙은 "단순화"될 수도 있습니다 . 단일 지시문으로 모두 수행할 수 있으므로 래퍼 가 필요하지 않습니다 RewriteRule.

예를 들어:

RewriteEngine On
RewriteRule ^/propostas/([^/]+)$ /subdir/propostas_usuarios/$1 [L]

정규식에 문자열 끝 앵커를 넣었습니다. 그렇지 않으면 형식의 URL과 일치합니다 /propostas/billy.joe/anything. 이는 $1첫 번째 캡처된 그룹에 대한 역참조입니다(즉,사용자 이름)에서RewriteRule 무늬.

L위에서 언급했듯이 현재 처리 중인 컨텍스트에서 추가 지시문을 방지하기 위해 플래그를 포함했습니다 . 그러나 <Directory>컨테이너(및 .htaccess)의 지시어는 계속 처리됩니다.

이전에 외부 리디렉션이 표시된 경우 테스트하기 전에 브라우저 캐시가 지워졌는지 확인해야 합니다.

관련 정보