2014-09-21 3 views
6

.htaccess 파일을 사용하여 요청 된 경로가 public/ 디렉토리의 파일인지 확인하고 싶습니다. 예, 제공된 경우 /index.php 앞으로 전달하십시오. 이 일을 할 수없는 것 같습니다. 여기 .htaccess : 정적 파일을 제공하고 다른 모든 파일을 index.php로 라우팅하십시오.

내가있어 무엇 :

Options +FollowSymLinks 
RewriteEngine on 

Options -Indexes 

RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f 
RewriteRule^%{DOCUMENT_ROOT}/public%{REQUEST_URI} [L] 

RewriteRule^index.php [QSA,L] 

예를 들어, http://example.com/css/style.css은 파일이 있기 때문에 /public/css/style.css이라는 아파치를 제공해야하지만 http://example.com/css/style.bad/index.php으로 보내야합니다.

답변

1

분명히 [L] does not work as I expected입니다.

RewriteEngine On 

RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f 
RewriteRule^public%{REQUEST_URI} [L] 

RewriteCond %{REQUEST_URI} !^/public/ 
RewriteRule^index.php [QSA,L] 
6

이 코드는 귀하의 측면 작동

Options +FollowSymLinks -MultiViews -Indexes 

RewriteEngine On 
RewriteBase/

RewriteCond %{DOCUMENT_ROOT}/public/$1 -f 
RewriteRule ^(.*)$ public/$1 [L] 

RewriteCond %{THE_REQUEST} \s/public/ [NC,OR] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^index.php [L,QSA] 
+0

에 예상대로 작동해야합니다 염두에두고, 시행 착오를 많이, 나는 작동 뭔가를 찾을 관리! 고맙습니다. 나는'style.css'가 *'/ css/style.css' *와 */public/css/style.css 둘 다에서 사용 가능하다는 것을 알았습니다. 기술적으로'후자는'/ public/public/css.style.css'가 파일이 아니기 때문에'index.php'로 전달해야합니다. 이것은 또한'/ public/xxx'가'index.php' 파일에서 설정 한 커스텀 커스텀 대신에 아파치 404를 던질 것을 의미합니다. 그걸 고칠 방법이 없니? – mpen

+1

귀하의 의견을 고려하여 내 대답을 편집했습니다 –

+1

당신은 내 소중한 마법입니다. 넌 나를 구했다. 고마워. –

관련 문제