본문으로 바로가기

* Override 허용

$ sudo vi /etc/httpd/conf/httpd.conf

$ sudo systemctl restart httpd

 

* 아파치 재시작해도 적용이 안된다면

$ sudo systemctl restart php-fpm

 

AllowOverride ALL

 

-----------------------------------------------------------------------

 

.htaccess 파일

 

서버 시간 바꾸기

php_value date.timezone 'Asia/Seoul'

 

 

Cross-Domain 허용

# Cross-Domain 허용
#<IfModule mod_headers.c> 
#    <FilesMatch "\.(ttf|ttc|otf|eot|woff|css)$"> 
#          Header set Access-Control-Allow-Origin "*" 
#    </FilesMatch> 
#</IfModule>

 

www 제거, www 강제로 붙이기 

#www 제거
#<IfModule mod_rewrite.c> 
#	RewriteEngine on 
#	RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
#	RewriteRule ^(.*)$ http://%1/$1 [L,R=301] 

# 또는

#   RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
#   RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]


# www 강제로 붙이기.
#	RewriteCond %{HTTP_HOST} .
#	RewriteCond %{HTTP_HOST} !^www\. [NC]
#	RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#</IfModule> 

 

 

https로 강제 적용 

<IfModule mod_rewrite.c>
RewriteEngine on
 
RewriteRule ^ - [E=protossl]
RewriteCond %{HTTPS} on
RewriteRule ^ - [E=protossl:s]
 
# https 강제이동.
# RewriteCond %{HTTPS} !=on
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 
</IfModule>

또는

<IfModule mod_rewrite.c>
	RewriteEngine on
	RewriteCond %{HTTP:X-Forwarded-Proto} !https
	RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

 

카페 24에서 오류 발생시 아래 코드 적용

RewriteEngine On

RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

 

 

https 강제 적용 + www 붙이기 (추세가 그런듯)


# https 강제 적용
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

# www 붙이기
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

 

 

특정 도메인으로 이동

<IfModule mod_rewrite.c>
	RewriteEngine on
	RewriteRule (.*) https://abc.com/$1 [R=301,L]
</IfModule>

 

 

 

브라우저로 접근할때 index.php 등의 기본파일이 없어서 디렉토리의 파일들이 노출될 경우

root의 .htaccess에 Options -Indexes 추가

 

 

특정 디렉토리의 접근 제한 ACL(Access Control List)

해당 디렉토리 안의 .htaccess에 

 

예) 111.222.333.444 만 접근 가능

RewriteEngine On

#오류시 특정 페이지로 이동
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php

<Files *>
	Order deny,allow
	Deny from all
	Allow from 111.222.333.444
</Files>

 

 

 

'[ Web 관련 ] > php' 카테고리의 다른 글

php 폴더 용량 조회 + DB 용량 조회  (0) 2020.12.02
PHPSTORM 단축키  (0) 2020.11.17
php 5.x 와 php 7.x 이슈  (0) 2020.11.11
php, mysql 테이블 존재 확인  (0) 2020.11.02
apache 에서 redirect (rewrite 모듈)  (0) 2020.10.21