- 하위폴더 .htaccess 설정
- .htaccess in subdirectory
- .htaccess in subfolder
1 문제상황[ | ]
- DOCUMENT_ROOT의 하위폴더에 .htaccess 파일을 설정하여 사용하고자 한다.
- 본 실습에서는 greet 폴더에 .htaccess 파일을 설정하여 http://zetawiki.com/greet/ 이하의 URL을 rewrite해본다.
- 본 실습에서의 DOCUMENT_ROOT는 /var/www/html
2 httpd.conf 설정[ | ]
- httpd.conf 파일 하단[1]에 아래 내용 추가
aconf
Copy
<Directory "/var/www/html/greet">
AllowOverride all
</Directory>
Console
Copy
[root@zetawiki ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
3 파일 작성[ | ]
- /var/www/html/greet/.htaccess 작성
aconf
Copy
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ sayhello.php?to=$1 [L]
- /var/www/html/greet/sayhello.php 작성
PHP
Copy
<?php
echo "안녕, [${_GET['to']}].";
4 테스트[ | ]
URL | 웹페이지 내용 |
---|---|
http://zetawiki.com/greet/ | 안녕, []. |
http://zetawiki.com/greet/너구리 | 안녕, [너구리]. |
http://zetawiki.com/greet/hello?world | 안녕, [hello]. |
http://zetawiki.com/greet/?hello | 안녕, []. |
http://zetawiki.com/greet/John_Snow | 안녕, [John_Snow]. |
http://zetawiki.com/greet/apple/banana/orange | 안녕, [apple/banana/orange]. |
http://zetawiki.com/greet/sayhello.php | 안녕, []. |
http://zetawiki.com/greet/sayhello.php?to=하나 | 안녕, [하나]. |
5 같이 보기[ | ]
6 주석[ | ]
7 참고[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.