Skip to content

.htaccess 야메로 사용하기 (via Mint)

여지껏 구글 애널리틱스를 통계용 프로그램(??)으로 사용하고 있었는데, 예전에 Mint를 쓰면서 알게 된 야메 auto insert 방식으로 js파일을 불러다가 넣고 있었다.

헌데 오늘 열심히 워드 플러긴 사이트를 돌아다니다가 보니 그런 헛수고 안해도 되는 플러긴도 있더라 ㅋ
게다가 Legacy Tracking Code를 고치기 귀찮아서 그대로 쓰고 있었는데, 이 플러긴이 알아서 새걸로 넣어주드만..


암튼 근데 지우긴 지우더라도 하는 방법은 기록해 놔야할 것 같아서..

1. PHP 파일을 하나 만든다.

민트꺼 훔친 거였다…
/js/auto.php를 만든다.

?Download php.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
< ?php
/******************************************************************************
 Mint
 
 Copyright 2004-2005 Shaun Inman. This code cannot be redistributed without
 permission from http://www.shauninman.com/
 
 More info at: http://www.haveamint.com/
 
 ******************************************************************************
 Attaches Mint JavaScript to all PHP-parsed pages automatically 
 ******************************************************************************/
function Minted($page) 
{
	$mint	= '
 
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-000000-0";  // 알아서 고치삼
urchinTracker();
</script>
 
 
 
	';
	$pages	= array(); // Add pages (relative to the public site root) that Mint should ignore
	$ip		= array(); // Add IP addresses that Mint should ignore
 
	if 
	(
		strpos($page,'frameset') !== false || 
		(!empty($ip) && in_array($_SERVER['REMOTE_ADDR'], $ip)) || 
		(!empty($pages) && in_array((isset($_SERVER['PHP_SELF']) && !empty($_SERVER['PHP_SELF']))?$_SERVER['PHP_SELF']:$_SERVER['SCRIPT_NAME'], $pages))
	)
	{
		return $page;
	}
 
	$replace = array
	(
		'</body>',
		'</BODY>'
	);
	return str_replace($replace, "{$mint}\r</body>", $page);
}
ob_start("Minted");
?>

body 태그가 닫히는 지점 앞에 스크립트를 자동으로 넣어주겠다는 얘기다.

2. .htaccess를 열어 PHP파일을 불러준다

?Download htaccess.txt
1
2
AddType application/x-httpd-php .html .htm
php_value auto_prepend_file /js/auto.php

근데 다 적고 나서 생각해보니까…
워드프레스의 영향권 밖에 있는 애들은 플러긴 코드가 자동으로 안들어가서 어차피 이거 계속 써야되네 ㅡ.ㅡ

ㅋㅋ

Leave a Reply

Type this numbers Enter this code

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>