2012-06-19 5 views
1

localhost/gallery/폴더에 사이트가 있습니다. 나는 이것을 만들고 싶어 : - localhost/gallery/12 real addres를 쓸 때 localhost/gallery/index.php가 될 것인가? url = 12 나는 그것을 만들려고했지만 불행히도 작동하지 않는다. 310 오류를 반환합니다 (ERR_TOO_MANY_REDIRECTS).어떻게? (.htaccess redirect 301)

AddDefaultCharset UTF-8 

Options +FollowSymlinks -Indexes 
RewriteEngine On 
RewriteCond %{THE_REQUEST} /index\.(php|html)\ HTTP/ 
RewriteRule ^index\.(php|html)$/[R=301,L] 
RewriteRule ^(.*)$ http://localhost/gallery/$1 [R=301,L] 

RewriteBase/

RewriteRule ^([^.]+)$ index.php?url=$1 [L,NC,QSA] 
+0

내가 게시 한 솔루션으로 문제가 해결되었는지 알려 주시겠습니까? – megaflop

답변

1

다음 줄은 실제로 외부 리디렉션을 강제로 : http://localhost/foobar에 대한 요청이 클라이언트를 알려주는 301 응답 될 수 있도록

RewriteRule ^(.*)$ http://localhost/gallery/$1 [R=301,L] 

http://localhost/gallery/foobar을 요청할 수 있습니다. 클라이언트가 이제 은 새로운 요청을에서 http://localhost/gallery/foobar으로 변경하여 http://localhost/gallery/gallery/foobar에 대한 301 응답을 얻게됩니다.

대신 사용해보십시오 : 나는 당신의 무한 루핑 규칙 전에 재 작성 조건을 추가 한

AddDefaultCharset UTF-8 

Options +FollowSymlinks -Indexes 
RewriteEngine On 
RewriteCond %{THE_REQUEST} /index\.(php|html)\ HTTP/ 
RewriteRule ^index\.(php|html)$/[R=301,L] 

RewriteCond %{REQUEST_URI} !^/gallery/ 
RewriteRule ^(.*)$ http://localhost/gallery/$1 [R=301,L] 

RewriteBase/
RewriteRule ^gallery/([^.]+)/?$ gallery/index.php?url=$1 [NC,QSA,L] 

참고 이미 리디렉션을 활성화에서/갤러리로 시작하는 URL을 중지 할 수 있습니다.

또한 설명대로 파일 이름을 http://localhost/gallery/foobar에서 http://localhost/gallery/index.php?url=foobar으로 바꿔 수정했습니다. 이 패턴의 /?은 선택적 후행 슬래시를 제공하므로 http://localhost/gallery/12http://localhost/gallery/12/이 모두 작동합니다. 후자를 원하지 않으면 패턴에서 /?을 제거하십시오.