같은 파일 .htaccess.template
가정 :
# BEFORE
# --- Start Part1 ---#
# --- End Part1 ---#
# AFTER
을하여 ColdFusion 스크립트가있다 같은 디렉토리에서 (이름은 중요하지 않음) htaccess.cfm
말 :
<!--- note double pound signs, necessary to escape in CF --->
<cfset start = "## --- Start Part1 ---##">
<cfset end = "## --- End Part1 ---##">
<cfsavecontent variable="replacement"><cfoutput>
I will appear between the start and end comments!
Replace me with what you want to appear in the .htaccess file.
</cfoutput></cfsavecontent>
<cfset template = fileRead(getDirectoryFromPath(getCurrentTemplatePath()) & "/.htaccess.template")>
<cfset startPos = find(start, template)>
<cfset endPos = find(end, template)>
<cfset before = left(template, startPos + len(start) - 1)>
<cfset after = right(template, len(template) - endPos + 1)>
<cfset content = "#before##replacement##after#">
<!--- <cfoutput><pre>#content#</pre></cfoutput> --->
<cfset path = getDirectoryFromPath(getCurrentTemplatePath()) & "/.htaccess">
<cfif fileExists(path)><cfset fileDelete(path)></cfif>
<cfset fileWrite(path, content)>
이 생성됩니다 같은 디렉토리에있는 파일 .htaccess
. 한 가지 문제는 삭제/덮어 쓰기를 방지하기 위해 .htaccess
에있는 파일 시스템 잠금을 처리하는 것으로 생각합니다.이 상황에서 어떤 작업을해야하는지 확신 할 수 없습니다. 이 예제의 .htaccess에서
은 다음과 같습니다
# BEFORE
# --- Start Part1 ---#
I will appear between the start and end comments!
Replace me with what you want to appear in the .htaccess file.
# --- End Part1 ---#
# AFTER