2012-02-13 1 views
4

내 로컬 컴퓨터의 d:\www\mysite 디렉토리에 웹 사이트가 있습니다. WAMPServer를 설치하고 내 사이트에 별칭 디렉토리 mysite을 설정했습니다.별칭 디렉토리를 통해 웹 사이트에 액세스하면 URL 재 작성이 작동하지 않습니다.

예를 들어 http://localhost/mysite/static-resource.htmld:\www\mysite\static-resource.html에있는 파일을 올바르게 검색합니다.

요청 된 URL을 찾을 수

하지 :

RewriteEngine On  
RewriteRule ^articles/(\d+) ./article.php?id=$1 

내가 http://localhost/mysite/articles/1에 액세스하려고 할 때, 나는이 응답을 얻을 :

내 문제는 URL 내 .htaccess 파일에 재 작성 함께 /www/mysite/article.php이 (가) 서버에서 발견되지 않았습니다.

d:\www\mysite\article.phparticle.php 파일이 있음을 확인했습니다. 과거

, 나는 (기본값 대신 c:\wamp\www의) 아파치 서버의 DocumentRoot로 설정 내 사이트 ( d:\www\mysite)의 루트가 있고, 그 시나리오에, 내 URL 때문에, 을 일 재 작성 내 현재 문제는 내 사이트가 별칭 디렉토리의 "배후"에 있다는 사실과 관련이 있어야합니다. 내 mysite.conf 파일의


내용 :

Alias /mysite/ "d:/www/mysite/" 

<Directory "d:/www/mysite/"> 
    Options Indexes FollowSymLinks MultiViews 
    AllowOverride all 
     Order allow,deny 
    Allow from all 
</Directory> 
+0

당신이'AllowOverride' 제대로 새 별칭 디렉토리 설정되어 있는지 확인 할 수 있나요? – clmarquart

+0

@clmarquart 무엇이 제대로 구성되어 있는지 잘 모르겠습니다. 관련 정보로 내 질문을 업데이트했습니다 ... –

답변

7

나는 당신의 재 작성 규칙에 RewriteBase를 볼 수 없습니다.
.htaccessRewriteBase 규칙을 추가하십시오.

RewriteEngine On  
RewriteBase /mysite/ 
RewriteRule ^articles/(\d+) ./article.php?id=$1 

RewriteBase 때문에 단지 http://localhost/mysite에 액세스하여 Alias /mysite/ "d:/www/mysite/"

경우, 그것은 not found on this server를 반환해야합니다의 /mysite/을 가지고있다. 이이 일이 같은 위의와 함께 또 다른 별칭을 추가하지 않으려면 :

Alias /mysite "d:/www/mysite/" 

또는

그냥이 :

AliasMatch /mysite(/.*)? d:/www/mysite/$1 

왜 RewriteBase를? RewriteBase Directive Apache Docs에서 :

RewriteBase 지시어를 명시 적으로 디렉토리 별 재 작성의 기본 URL을 설정합니다. 아래에서 볼 수 있듯이 RewriteRule은 디렉토리 별 구성 파일 (.htaccess)에서 사용할 수 있습니다. 이 경우 로컬로 작동하고 처리하기 전에 로컬 디렉토리 접두사를 제거하고 나머지에만 다시 쓰기 규칙을 적용합니다. 처리가 완료되면 접두어가 자동으로 경로에 다시 추가됩니다.기본 설정은; RewriteBase physical-directory-path

새 URL에 대해 대체가 발생하면이 모듈은 URL을 서버 처리에 다시 주입해야합니다. 이를 수행하려면 해당 URL 접두사 또는 URL 기반이 무엇인지 알아야합니다. 기본적으로이 접두어는 해당 파일 경로 자체입니다. 그러나 대부분의 웹 사이트에서 URL은 실제 파일 이름 경로와 직접 관련이 없으므로이 가정은 종종 잘못됩니다! 따라서 RewriteBase 지정 문을 사용하여 올바른 URL 접두사를 지정할 수 있습니다. RewriteBase Directive Apache Docs에서

예 :

# 
# /abc/def/.htaccess -- per-dir config file for directory /abc/def 
# Remember: /abc/def is the physical path of /xyz, i.e., the server 
#   has a 'Alias /xyz /abc/def' directive e.g. 
# 

RewriteEngine On 

# let the server know that we were reached via /xyz and not 
# via the physical path prefix /abc/def 
RewriteBase /xyz 

# now the rewriting rules 
RewriteRule ^oldstuff\.html$ newstuff.html 
+0

'RewriteBase', 알겠습니다. Thanks':)' –

+0

@ imeVidas 환영합니다. – ThinkingMonkey

+0

'RewriteBase'를 생략하거나'.htaccess'가 위치한 디렉토리로 설정할 수 있습니까? – kongr45gpen