나의 마음을 ctrl+c,너의 가슴에 ctrl+v

[CodeInteger] htaccess

oss2015. 10. 13. 19:30

.htaccess
CodeInteger 의 하부속성이 아닌, Apache URI 정책


RewriteEngine On
mod_rewriting 을 활성화하여 localhost/layout/a/b/c 와 같은 주소가 가능

RewriteRule ^([^\.]+)$ ./index.php?params=$1 [L]
URL에 어떤 파라미터나 주소가 입력되어도 이를 index.php에 url 파라미터의 값으로 대입하여 링크를 만들고 이 주소로 이동처리가 가능.

Example) http://localhost/layout/abc -> http://localhost/?index.php?params=layout/a/123

* 설정시 참조
^([^\.]+)$ : 주소 끝에 입력되는 모든 문자열을 받아낸다. 이 문자열들은 뒤의 $1로 캐치한다.
L flag : rewrite rule이 끝남을 표시


 Sample


# 404 error document

ErrorDocument 404 /errdoc/error_404

RewriteEngine on

# data/index.php 페이지 변경
RewriteRule ^data\/index\.php$ /main/blank [R=301]

# 도메인에서 www 제거
# RewriteCond %{REQUEST_URI} ^/admin/(.*)$
# RewriteCond %{REQUEST_URI} ^/selleradmin/(.*)$
# RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
# RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# CI 리다이렉트 - 아래 폴더는 바로 접근됨
RewriteCond $1 !^(index\.php|images|robots\.txt|crossdomain\.xml|sitemap\.xml)
RewriteCond %{REQUEST_URI} !^/app/javascript/(.*)$
RewriteCond %{REQUEST_URI} !^/phpThumb/(.*)$
RewriteCond %{REQUEST_URI} !^/data/(.*)$
RewriteCond %{REQUEST_URI} !^/admin/skin/(.*)$
RewriteCond %{REQUEST_URI} !^/selleradmin/skin/(.*)$
RewriteCond %{REQUEST_URI} !^/board_original/(.*)$
RewriteCond %{REQUEST_URI} !^/pg/(.*)$
RewriteRule ^((.*))$ index.php?/$1 [L]