문제

나는 Jekyll로 생성된 사이트를 배포하려고 하는데 사이트를 내 서버의 자체 하위 폴더에 보관하여 모든 것을 더 체계적으로 유지하고 싶습니다.

기본적으로 다음 내용을 사용하고 싶습니다. /jekyll 유사한 이름의 파일이 실제 웹 루트에 존재하지 않는 한 루트로 사용됩니다.그래서 뭔가 /jekyll/sample-page/ 다음과 같이 표시됩니다. http://www.example.com/sample-page/, 반면에 /other-folder/ 다음과 같이 표시됩니다. http://www.example.com/other-folder.

내 테스트 서버는 Apache 2.2와 다음을 실행합니다. .htaccess (에서 적응 http://gist.github.com/97822) 완벽하게 작동합니다.

RewriteEngine On

# Map http://www.example.com to /jekyll.
RewriteRule ^$ /jekyll/ [L]

# Map http://www.example.com/x to /jekyll/x unless there is a x in the web root.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/jekyll/
RewriteRule ^(.*)$ /jekyll/$1

# Add trailing slash to directories without them so DirectoryIndex works.
# This does not expose the internal URL.
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} !/$
RewriteRule ^(.*)$ $1/

# Disable auto-adding slashes to directories without them, since this happens
# after mod_rewrite and exposes the rewritten internal URL, e.g. turning
# http://www.example.com/about into http://www.example.com/jekyll/about.
DirectorySlash off

하지만 내 프로덕션 서버는 Apache 1.3을 실행하는데, 이는 다음을 허용하지 않습니다. DirectorySlash.비활성화하면 내부 리디렉션 과부하로 인해 서버에서 500 오류가 발생합니다.

ReWriteConds 및 규칙의 마지막 섹션을 주석 처리하면 다음과 같습니다.

RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} !/$
RewriteRule ^(.*)$ $1/

...모든 것이 대부분 작동합니다. http://www.example.com/sample-page/ 올바른 내용을 표시합니다.그러나 후행 슬래시를 생략하면 주소 표시줄의 URL이 실제 내부 URL 구조를 노출합니다. http://www.example.com/jekyll/sample-page/

다음과 같은 유용한 도구가 있는 Apache 1.3에서 디렉토리 슬래시를 설명하는 가장 좋은 방법은 무엇입니까? DirectorySlash 존재하지 않나요?어떻게 사용할 수 있나요? /jekyll/ 실제 URL 구조를 공개하지 않고 디렉토리를 사이트 루트로 사용하시겠습니까?

편집하다:

Apache 1.3에 대해 엄청나게 연구한 후에 이 문제는 본질적으로 다음 페이지에 나열된 두 가지 다른 문제의 조합이라는 것을 발견했습니다. Apache 1.3 URL 재작성 가이드.

(부분적으로) 이동된 DocumentRoot가 있는데, 이론적으로는 다음과 같이 처리됩니다.

RewriteRule   ^/$  /e/www/  [R]

또한 악명 높은 "후행 슬래시 문제"가 있는데, 이는 다음을 설정하여 해결됩니다. RewriteBase (아래 응답 중 하나에서 제안된 대로):

RewriteBase    /~quux/
RewriteRule    ^foo$  foo/  [R]

문제는 이 둘을 결합하는 것이다.문서 루트 이동은 사용하지 않습니다 (할 수 없습니까?) RewriteBase—후행 슬래시를 수정하려면(?) 그것이 필요합니다… 흠…

도움이 되었습니까?

해결책

일주일간의 노력 끝에 드디어 얻었습니다.RewriteRules는 정말 부두입니다…

RewriteEngine On

# Map http://www.example.com to /jekyll.
RewriteRule ^$ /jekyll/ [L]

# Map http://www.example.com/x to /jekyll/x unless there is a x in the web root.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/jekyll/
RewriteRule ^(.*)$ /jekyll/$1

# Add trailing slash to directories within jekyll
# This does not expose the internal URL.
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule ^jekyll/(.*[^/])$ http://www.example.com/$1/ [R=301]

필요하지 않습니다 DirectorySlash.마술처럼 모든 것이 작동합니다.

다른 팁

다음을 간단히 사용할 수 있습니다.

RewriteBase   /jekyll

그리고 모든 것은 그 지점에서부터 시작됩니다.

나를 위해 일한 유일한 간단한 해결책은 여기

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain-name.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain-name.com$
RewriteCond %{REQUEST_URI} !folder/
RewriteRule (.*) /folder/$1 [L]

이 코드를 .htaccess 파일에 넣으세요.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top