2014-07-22 3 views
1

나는 하나의 index.html 파일로 구성된 웹 사이트를 운영하고 있습니다. 몇 가지 메뉴가 있으며 3 단계로 깊게 갈 필요가 있으므로 PHP와 같은 구조를 원합니다 : index.html?main=$1&secondary=$2&tertiary=&3. 이 값을 www.example.com/$1/$2/$3으로 줄여야합니다. 전반적으로 아주 간단 나는 .htaccess에 대한 다음과 같은 규칙을 사용하여 생각 :.htaccess 디렉토리 문제 제외

RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)?$ index.html?main=$1&secondary=$2&tertiary=$3 
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)?$ index.html?main=$1&secondary=$2 
RewriteRule ^([A-Za-z0-9-]+)?$ index.html?main=$1 

지금, 나는 또한 영향을받지 않습니다 내 루트 폴더에 여러 폴더가, 그렇지 않으면 내이의 실 거예요 작업을 포함한다. this answer에서 다른 규칙보다 먼저 RewriteRule ^(bower_components|photos)($|/) - [L]을 사용하여이 폴더를 제외하려고 시도했지만 작동하지 않았습니다. 나는 또한 this answer을 시도했는데 .htaccess은 cont이고 내 폴더에 넣었습니다. 성공하지 못했습니다. 그래서 분명히 어딘가에서 뭔가 잘못하고 있습니다.

Folder Layout

여기 내 현재 .htaccess 파일입니다 : 내가 http://localhost/myProject/activities에 가면 지금

Options +FollowSymLinks 
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule .* - [L] 

RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)?$ index.html?main=$1&secondary=$2&tertiary=$3 
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)?$ index.html?main=$1&secondary=$2 
RewriteRule ^([A-Za-z0-9-]+)?$ index.html?main=$1 

index.html 수 있도록 한 수준 깊은 내 폴더 레이아웃을 표시하려면, 여기의 빠른 스냅 샷입니다 파일은 myProject에 있으며 작동하며 모든 포함이 올바르게 포함되어 있습니다. 그러나 http://localhost/myProject/activities/test으로 갈 때 기본 index.html 페이지가 표시되지만 내 포함 지점은 http://localhost/myProject/activities/bower_components/platform/platform.js이므로 activities이 너무 많습니다.

답변

1

다음과 같은 규칙을 계속 :

Options +FollowSymLinks 
RewriteEngine On 
RewriteBase /myProject/ 

RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule .* - [L] 

RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.html?main=$1&secondary=$2&tertiary=$3 [L,QSA] 
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.html?main=$1&secondary=$2 [L,QSA] 
RewriteRule ^([A-Za-z0-9-]+)/?$ index.html?main=$1 [L,QSA] 

그런 다음 CSS/JS/영상 포함을 위해 당신의 CSS에서 절대 경로를 사용, JS, 이미지 파일이 아닌 상대 하나. 즉,이 파일의 경로가 http:// 또는 슬래시 /으로 시작해야합니다.

페이지의 HTML 헤더에 <base href="/myProject/" />을 추가하여 모든 상대 URL이 현재 URL이 아닌 해당 URL에서 처리되도록 할 수 있습니다.

+0

''를 사용하면 트릭을 멋지게 처리하는 것처럼 보입니다! 모든 링크를 다시 작성하는 것보다 선호하십시오. 감사! – jdepypere

+0

정말 다행입니다. – anubhava