작은숲:위키노트/아파치 mod rewrite 모듈: 두 판 사이의 차이
잔글 (문자열 찾아 바꾸기 - "<source" 문자열을 "<syntaxhighlight" 문자열로) |
잔글 (문자열 찾아 바꾸기 - "</source>" 문자열을 "</syntaxhighlight>" 문자열로) |
||
| 4번째 줄: | 4번째 줄: | ||
<syntaxhighlight lang="apache"> | <syntaxhighlight lang="apache"> | ||
RewriteRule ^redirect$ ./redirect.php?target=%{QUERY_STRING} [L] | RewriteRule ^redirect$ ./redirect.php?target=%{QUERY_STRING} [L] | ||
</ | </syntaxhighlight> | ||
이렇게 하면 쿼리 문자열로 넘어온 값을 <code>$_GET['target']</code>에 값을 넣어 제대로 넘어온다. | 이렇게 하면 쿼리 문자열로 넘어온 값을 <code>$_GET['target']</code>에 값을 넣어 제대로 넘어온다. | ||
== RewriteRule의 QSA 플래그 == | == RewriteRule의 QSA 플래그 == | ||
| 25번째 줄: | 25번째 줄: | ||
# from http://example.com/page.php?foo=bar | # from http://example.com/page.php?foo=bar | ||
# to http://example.com/target.php?foo=bar&bar=baz | # to http://example.com/target.php?foo=bar&bar=baz | ||
</ | </syntaxhighlight> | ||
== 참고 == | == 참고 == | ||
* [https://wiki.apache.org/httpd/RewriteQueryString Manipulating the Query String] | * [https://wiki.apache.org/httpd/RewriteQueryString Manipulating the Query String] | ||
2021년 3월 28일 (일) 12:54 판
RewriteRule에서의 QUERY_STRING과 PHP
/redirect?http://m.naver.com으로 접근하면 뒤에 붙은 URL로 리다이렉트 시키는 기능을 만들고자 한다. 하지만 쿼리 문자열로 URL을 넘겨주면 $_GET 변수에 키로 URL이 저장되고 URL에 포함된 .은 _으로 변경된다. 즉, $_GET['http://m_naver_com']에 빈 문자열이 들어가서 넘어온다. 이를 해결하기 위한 방법.
RewriteRule ^redirect$ ./redirect.php?target=%{QUERY_STRING} [L]
이렇게 하면 쿼리 문자열로 넘어온 값을 $_GET['target']에 값을 넣어 제대로 넘어온다.
RewriteRule의 QSA 플래그
RewriteRule에 QSA 플래그를 주면 본래 넘어온 쿼리 문자열을 그대로 추가해서 넘겨주게 된다.
# Keep original query (default behavior)
RewriteRule ^page\.php$ /target.php [L]
# from http://example.com/page.php?foo=bar
# to http://example.com/target.php?foo=bar
# Discard original query
RewriteRule ^page\.php$ /target.php? [L]
# from http://example.com/page.php?foo=bar
# to http://example.com/target.php
# Replace original query
RewriteRule ^page\.php$ /target.php?bar=baz [L]
# from http://example.com/page.php?foo=bar
# to http://example.com/target.php?bar=baz
# Append new query to original query
RewriteRule ^page\.php$ /target.php?bar=baz [QSA,L]
# from http://example.com/page.php?foo=bar
# to http://example.com/target.php?foo=bar&bar=baz
참고
- Manipulating the Query String
- Moving path information to a query string - simple
- Apache RewriteRule and query string