2011-09-23 4 views
4

기본적으로 CDN 설정이 있습니다.어떻게 모든 하위 폴더와 디렉토리를 파일을 제외한 기본 루트로 리디렉션합니까?

/public_html/ 
index.html 

/files/ 
image/ 
video/ 
video2/video2 

내가 메인 폴더에 모든 하위 폴더 및 디렉토리를 재 지정하려는 - 파일 확장자를 제외하고, 그래서 누군가가 파일을로드하는 경우, 그 부하에, 너무 사람 캔트보기 디렉토리를합니다. (나는 404 페이지 나 금지 된 메시지를보고 싶지 않다. 단지 메인 페이지로 가기를 원한다.)

index.php를 리다이렉트하는 것을 막을 수있다. .htaccess로이 작업을 수행 할 수 있습니까?

+0

네 당신의 .htaccess 어떻게 생겼는지 수행을? –

+0

아무 것도하지 않았습니다 ... 그냥 WWW에서 – TheBlackBenzKid

+0

을 제거 했으니까요. /video.mpeg (URL에 누군가 액세스 파일 보내기) -> /media/video.mpeg (실제 파일)? –

답변

6
# don't show any files in the folder 
IndexIgnore * 

ErrorDocument 403/
ErrorDocument 404/

RewriteEngine On 

# disabled user to access directly to the files folder. 
RewriteRule ^files(\/?)$ - [F] 

# images 
RewriteRule ^image/(.*)\.(jpg|png|jpeg|gif)$ /files/$1.$2 [L] 
# video 
RewriteRule ^video/(.*)\.(flv|avi|mov)$ /files/$1.$2 [L] 
#etc... 

당신이 하위 폴더가있는 경우 (.*)가 자동으로 사용합니다. 예 : 다음

http://www.domain.com/image/i.png => /files/i.png 

http://www.domain.com/image/sub1/sub2/i.png => /files/sub1/sub2/i.png 

도움이 될 몇 가지 링크 :

http://www.javascriptkit.com/howto/htaccess.shtml

http://www.htaccess-guide.com/

http://net.tutsplus.com/tutorials/other/the-ultimate-guide-to-htaccess-files/

http://www.bloghash.com/2006/11/beginners-guide-to-htaccess-file-with-examples/

+0

내 URL에 넣으면 어떻게됩니까 : http://www.domain.com/image/sub1/ 또는이 http : // www .domain.com/image/sub1/sub2/ – TheBlackBenzKid

+1

표준 404 from/image/sub1/폴더. 404 및 403 메시지를 사용자 정의하는 것이 좋습니다. 이 하나는 404이고 누군가가 직접/files /에 액세스하면 403 (내 업데이트 된 답변보기) –

+0

루트 대신 ALL 404 및 403을 리디렉션 할 수 있습니까? – TheBlackBenzKid

관련 문제