2017-05-01 11 views
1

현재 모든 트래픽이 내 사이트의 www. 버전으로 리디렉션됩니다. 그러나 특정 폴더의 리디렉션 된 링크를 확인하면 문제가 될 수도 있고 아닐 수도있는 문제를 발견했습니다.www가 아닌 ​​리디렉션 및 후행 슬래시가있는 htaccess 문제

기본적으로 www.example.com/example/examplepage/에 헤더 체크를하면 200 OK가 표시됩니다.

www.example.com/example/examplepage (후행없이 /)을 선택하면 위에 설명한대로 301 리디렉션이 표시됩니다. 내가 example.com/example/examplepage/ (www없이)를 확인하면

하지만, 그 다음 www.example.com/example/examplepage/ (올바른 페이지)로 리디렉션하는 ... www.example.com/example/examplepage.php로 리디렉션합니다.

이 정보가 도움이 되었기를 바랍니다.

) 이것은 괜찮습니까?
b) 내 .htaccess에 누락 된 것이 있습니까?

RewriteOptions inherit 
RewriteEngine On 

RewriteCond %{THE_REQUEST} ^.*/index.htm 
RewriteRule ^(.*)index.htm$ http://www.example.com/$1 [R=301,L] 

RewriteCond %{HTTP_HOST} ^example\.com [NC] 
RewriteRule (.*) http://www.example.com/$1 [R=301,L] 


RewriteCond %{THE_REQUEST} \.php 
RewriteRule ^tips/([^.]+)\.php$ http://www.example.com/example/$1/ [R=301,L] 

RewriteRule ^tips/([^.]+[^./])$ http://www.example.com/example/$1/ [R=301,L] 

RewriteRule ^(tips/[^.]+)/$ /$1.php [L] 

참고 : 위의 PHP 규칙을 특정 폴더에 .php 확장을 "숨"을 만들었습니다 (그들을 다른 곳 숨겨진 싶지 않았다).

+0

그것은 왜'www.example 명확하지 않다 ... 그것은 다른 사람이 등 회색 것, 머리를 당겨 전체 주말을 낭비 방지 희망에 가능한 한 여기에 많은 세부 사항을 추가하는 시도했습니다. com/example/examplepage'가 리디렉션되어야합니다 (즉, 모든 URL이 후행 슬래시로 끝나야 함을 의미). 그러나 지시어에 따르면'/ tips /'를 시작하는 URL 경로 만 리다이렉트 할 것인가? – MrWhite

+0

예, 맞습니다.이 리디렉션은/tips 폴더에만 적용됩니다. 아마 내가 "팁"참조가 example.com 참조와 일치하도록 "예제"로 변경되어야한다고 명확히해야했습니다. 미안하지만 말이 되길 바랄 것입니다. – Lee

+0

예제를 변경하여 "example.com/example/examplepage /'(www가없는 경우)를 확인하면 www.example.com/example/examplepage.php'로 리디렉션됩니다. "- 귀하가 게시 한 지침에서 어떻게 그러한 일이 발생하는지 보지 못합니까? – MrWhite

답변

0

나는 그럭저럭 (잘, ok- 운이 좋은 추측를 얻는다) 그것을 해결할 수 있었다. 그러나 어느 쪽의 방법이라도, 그것은 지금 일하는 것처럼 보인다. 이것은 지금 결과

RewriteEngine On 
RewriteCond %{THE_REQUEST} \.php 
RewriteRule ^tips/([^.]+)\.php$ http://www.example.com/tips/$1/ [R=301,L] 
RewriteRule ^tips/([^.]+[^./])$ http://www.example.com/tips/$1/ [R=301,L] 
RewriteCond %{THE_REQUEST} ^.*/index.htm 
RewriteRule ^(.*)index.htm$ http://www.example.com/$1 [R=301,L] 

RewriteCond %{HTTP_HOST} ^example\.com [NC] 
RewriteRule (.*) http://www.example.com/$1 [R=301,L] 

RewriteRule ^(tips/[^.]+)/$ /$1.php [L] 

: 나는 다음을 표시하는 위의 규칙 순서를 적용했습니다

  1. http://example.com/tips/examplepage.php (www와 버전)
  2. http://example.com/tips/examplepage - 슬래시 (www와 버전) 후행하지 않고

모든 마침내

012 (슬래쉬와) www.example.com/tips/examplepage/하는 리디렉션

또한 www.example.com/examplepage.php ("tips"폴더가 아닌)가 확장자를 유지합니다.

또한/(www와 non-www를 모두 사용하여)에 index.htm을 다시 씁니다.

나는