.htaccess RewriteRule이 작동하지 않는 방법
나는이 RewriteRule
A의 .htaccess
아무것도하지 않는 파일입니다. 이 문제를 어떻게 해결합니까?
.htaccess
Apache가 파일을 읽고 준수 하는지 확인하려면 어떻게 해야합니까? 에코가 "작동 중"메시지를 작성할 수 있습니까? 쓰면 해당 라인이 에코되는 위치는 어디입니까?.htaccess
파일을 사용하지 않는 경우 Apache 에서 파일을 사용하려면 어떻게해야합니까?- (가) 경우
.htaccess
사용되는하지만 내가RewriteRule
여전히 영향을하지 않습니다, 나는 디버그에 더 무엇을 할 수 있습니까?
당신에 일부 정크 값을 입력 .htaccess
예를 들어 foo bar
, sakjnaskljdnas
어떤 키워드가 없습니다 htaccess로 인식하고 URL을 방문하십시오. 그것이 작동하면, 당신은 얻을
500 내부 서버 오류
인터넷 서버 오류
서버에 내부 오류 또는 구성 오류가 발생하여 요청을 완료 할 수 없습니다 ...
나는 당신이 곧 그것을 넣을 것을 제안합니다 RewriteEngine on
.
당신은 당신의 컴퓨터에 있기 때문에. 아파치 .conf
파일에 액세스 할 수 있다고 가정 합니다.
.conf
파일을 열고 다음 과 비슷한 줄을 찾으십시오.
LoadModule rewrite_module modules/mod_rewrite.so
주석이 달린 경우 (#) 주석을 해제하고 아파치를 다시 시작하십시오.
다시 쓰기를 기록하려면
RewriteEngine On
RewriteLog "/path/to/rewrite.log"
RewriteLogLevel 9
위에 3 줄을 입력하십시오 virtualhost
. httpd를 다시 시작하십시오.
RewriteLogLevel 9
Level에 높은 값을 사용하면 Apache 서버 속도가 크게 느려집니다! 디버깅시에만 2보다 큰 레벨에서 재기록 로그 파일을 사용하십시오! 레벨 9는 거의 모든 재기록 로그 세부 사항을 기록합니다.
최신 정보
Apache 2.4에서 변경된 사항 :
FROM 2.2에서 2.4로 업그레이드
RewriteLog 및 RewriteLogLevel 지침은 제거되었습니다. 이 기능은 이제 LogLevel 지시문을 사용하여 mod_rewrite 모듈에 대한 적절한 수준의 로깅을 구성하여 제공됩니다 . mod_rewrite 로깅 섹션도 참조하십시오.
LogLevel에 대한 자세한 내용은 LogLevel 지시문을 참조하십시오.
당신은 달성 할 수 있습니다
RewriteLog "/path/to/rewrite.log"
이런 식으로 지금
LogLevel debug rewrite_module:debug
'일부 정크 값 입력'답변이 저에게 속임수를 쓰지 않았습니다. 입력 한 정크에도 불구하고 내 사이트가 계속로드되었습니다.
대신 .htaccess 파일 맨 위에 다음 줄을 추가했습니다.
deny from all
.htaccess가 선택되어 있는지 여부를 신속하게 알려줍니다. .htaccess를 사용하는 경우 해당 폴더의 파일이 전혀로드되지 않습니다.
일반적으로 .htaccess의 변경 사항은 가시적 인 효과를 가져야합니다. 효과가 없으면 구성 아파치 파일을 확인하십시오.
<Directory ..>
...
AllowOverride None
...
</Directory>
로 변경해야합니다
AllowOverride All
또한 .htaccess 파일에서 지시문을 변경할 수 있습니다.
아마도 더 논리적 인 방법은 파일 (예 : test.html)을 만들고 일부 내용을 추가 한 다음 색인 페이지로 설정하는 것입니다.
DirectoryIndex test.html
대부분의 경우 .htaccess 규칙은 디렉토리 / 파일 수준에서 작업하는 Apache 구성을 재정의합니다.
세 가지 질문 중 첫 번째 질문에 대답하기 위해 .htaccess 파일이 작동하는지 여부를 확인하는 간단한 방법은 .htaccess 파일 맨 위에서 사용자 정의 오류를 트리거하는 것입니다.
ErrorDocument 200 "Hello. This is your .htaccess file talking."
RewriteRule ^ - [L,R=200]
On to your second question, if the .htaccess file is not being read it is possible that the server's main Apache configuration has AllowOverride
set to None
. Apache's documentation has troubleshooting tips for that and other cases that may be preventing the .htaccess from taking effect.
Finally, to answer your third question, if you need to debug specific variables you are referencing in your rewrite rule or are using an expression that you want to evaluate independently of the rule you can do the following:
Output the variable you are referencing to make sure it has the value you are expecting:
ErrorDocument 200 "Request: %{THE_REQUEST} Referrer: %{HTTP_REFERER} Host: %{HTTP_HOST}"
RewriteRule ^ - [L,R=200]
Test the expression independently by putting it in an <If>
Directive. This allows you to make sure your expression is written properly or matching when you expect it to:
<If "%{REQUEST_URI} =~ /word$/">
ErrorDocument 200 "Your expression is priceless!"
RewriteRule ^ - [L,R=200]
</If>
Happy .htaccess debugging!
If you have access to apache bin directory you can use,
httpd -M
to check loaded modules first.
info_module (shared) isapi_module (shared) log_config_module (shared) cache_disk_module (shared) mime_module (shared) negotiation_module (shared) proxy_module (shared) proxy_ajp_module (shared) rewrite_module (shared) setenvif_module (shared) socache_shmcb_module (shared) ssl_module (shared) status_module (shared) version_module (shared) php5_module (shared)
After that simple directives like Options -Indexes
or deny from all
will solidify that .htaccess are working correctly.
To test your htaccess rewrite rules, simply fill in the url that you're applying the rules to, place the contents of your htaccess on the larger input area and press "Test" button.
Why not put some junk in your .htaccess file and try to reload apache. If apache fails to start you know its working. Remove the junk then reload apache if it loads congrats you configured .htaccess correctly.
참고URL : https://stackoverflow.com/questions/9234289/how-to-debug-htaccess-rewriterule-not-working
'Programing' 카테고리의 다른 글
전체 화면을 채우시겠습니까? (0) | 2020.07.27 |
---|---|
전체 심볼릭 링크 경로를 보는 방법 (0) | 2020.07.27 |
`testl` eax와 eax? (0) | 2020.07.27 |
오류에서 localhost를 해제하는 방법 : EADDRINUSE 듣기 (0) | 2020.07.26 |
Java에서 문자열을 동일한 길이의 하위 문자열로 분할 (0) | 2020.07.26 |