2017-09-28 1 views
1

일부 웹 사이트가있는 공유 호스팅에 있습니다..htaccess를 사용하여 CSS | js | img | fonts 폴더 리디렉션

이 서버에서 루트 (dir name = site)의 디렉토리에 ZendFramework2를 추가해야합니다. 컨트롤러 및 작업이 올바르게 작동하지만 CSS, 이미지 또는 자바 스크립트를로드 할 수 없습니다. 여기

내 디렉토리입니다 :/사이트 폴더에

/root/website1 (example.com/website1) 
/root/website2 (example.com/website2) 
/root/site  (example.com/site) 
/root/site/application 
/root/site/data 
/root/site/library 
/root/site/public 
/root/site/public/css 
/root/site/public/fonts 
/root/site/public/img 
/root/site/public/js 
/root/site/public/.htaccess 
/root/site/.htaccess 

.htacces에서

RewriteEngine On 

RewriteRule ^\.htaccess$ - [F] 

RewriteCond %{REQUEST_URI} ="" 
RewriteRule ^.*$ /site/public/index.php [NC,L] 

RewriteCond %{REQUEST_URI} !^/site/public/.*$ 
RewriteRule ^(.*)$ /site/public/$1 

RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule ^.*$ - [NC,L] 

RewriteRule ^site/public/.*$ /site/public/index.php [NC,L] 

.htacces가/사이트/공용 폴더

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ /site/index.php [NC,L] 

CSS 태그 :

<link href="/css/global.css" rel="stylesheet" type="text/css" media="screen" /> 

/css/global.css를 /site/public/css/global.css를로드하도록 리디렉션 할 수 있습니까?

물론, 내가 ... 대한

<link href="/site/css/global.css" rel="stylesheet" type="text/css" media="screen" /> 

을 변경할 수 있습니다 ...하지만 난

어떤 도움은 매우 환영 href가 변경하지 않으려는!

+0

죄송합니다. http://example.com/은/root 또는/root/site 또는/root/site/public입니다. – Webdesigner

+0

공용 디렉토리는 보호 전용입니다. 사용자가보아야하는 모든 것이 거기에 있습니다 (이미지, 스크립트, CSS, 글꼴). 공개되지 않은 모든 것은 디렉토리 수준으로 보호되는 서버 측 코드 및 구성입니다. – BigPino

+0

네,이 사실을 알고 있지만,/root/site/public이 example.com/css/global.css보다 실제 공용 폴더 일 경우에는 그 질문에 답하지 않습니다. 그러나 이것이 사실이 아니기 때문에, 루트 디렉토리 란 무엇입니까? 그것은/root 또는/root/site입니다. – Webdesigner

답변

2

모든 문제를 해결하기 위해 하나의 .htaccess 파일 만 생성합니다. 이것을/root 폴더에 넣고 다른 .htaccess 파일을 삭제하십시오.

# This first part should be done by the webserver, 
# if not than thing about to change you hoster but I put it here: 
# Preventing direct access to any .ht file (.htaccess, .htpasswd, etc.) 
<FilesMatch "^\.ht"> 
    Require all denied 
</FilesMatch> 

Options +FollowSymlinks 
Options -Indexes 

# Start to Rewrite 
RewriteEngine On 

# For all URL starting with /css, /fonts, /img or /js 
RewriteCond %{REQUEST_URI} ^/?(css|fonts|img|js)(/.*)?$ [NC] 
RewriteRule ^.*$ /site/public/%1%2 [L] 

# Redirect all to the Application if not done already 
RewriteCond %{REQUEST_URI} !^/?site/public/index\.php [NC] 
# but not if the URL starts with css, fonts, img or js 
RewriteCond %{REQUEST_URI} !^/?(css|fonts|img|js)(/.*)?$ [NC] 
# or if request is a real file 
RewriteCond %{REQUEST_FILENAME} !-f 
# or if request is a real directory but not the root directory 
RewriteCond %{REQUEST_URI} ^/?$ [OR] 
RewriteCond %{REQUEST_FILENAME} !-d 
# Rewrite the rest to the index.php file in your public folder 
RewriteRule ^.*$ /site/public/index.php [NC,L] 
+0

그 일을하게!시간 내 주셔서 대단히 감사합니다. 정말 고맙습니다. – BigPino

관련 문제