2016-07-27 4 views
0

불행히도 문제가 있습니다.htaccess url 다시 쓰기 : 후행 슬래시를 추가해도 작동하지 않습니다.

각 URL 뒤에 슬래시가 추가되고 301을 통해 슬래시가없는 버전이 슬래시가있는 변형으로 리디렉션됩니다.

이전에는 URL 재 작성이 성공적으로 제거되고 SSL이 적용된 html 파일 확장자가 있습니다.

그래서 다음 코드를 사용하여 슬래시를 추가했습니다.

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*[^/])$ /$1/ [L,R=301] 

나는이 스레드에서이 솔루션을 발견 : 그것은 불행하게도 효과가 남아 Htaccess: add/remove trailing slash from URL

.

흥미롭게도, 나는, 예를 들어, (끝에 슬래시) 다음 URL을 방문 할 때 :

example.com/imprint/

나는 다음과 같은 메시지가 : 요청 된 URL이 아니었다 이 서버의 /imprint.html/을 찾았습니다.

imprint.html ???

나는 희망
RewriteEngine On 

#Activate and force ssl and redirect from non-www to www# 
RewriteCond %{HTTP_HOST} ^example\.com$ [NC,OR] 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC] 

#Removes HTMl-Extension and make URLs clean# 

#example.com/page will display the contents of example.com/page.html 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule ^(.+)$ $1.html [L,QSA] 

#301 from example.com/page.html to example.com/page 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/ 
RewriteRule ^(.*)\.html$ /$1 [R=301,L] 

#Redirect Index Files e.g. /index or /index.html 
RewriteRule ^index\.html$/[R=301,L] 
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L] 

#Adds a trailing slash 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*[^/])$ /$1/ [L,R=301] 

, 당신이 나를 도울 수 :

은 여기 내 전체 htaccess로 파일입니다. :-)

답변

0

!-f (파일 아님)을 검사하면 .html 파일도 건너 뜁니다. 사용할 수 있습니다 [OR]

RewriteEngine On 

#Activate and force ssl and redirect from non-www to www# 
RewriteCond %{HTTP_HOST} ^example\.com$ [NC,OR] 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*?)/?$ https://www.example.com/$1/ [L,R=301] 

#301 from example.com/page.html to example.com/page 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/ 
RewriteRule ^(.+)\.html/?$ /$1/ [R=301,L] 

#Redirect Index Files e.g. /index or /index.html 
RewriteRule ^index\.html/?$/[R=301,L] 

RewriteRule ^(.+)/index\.html/?$ /$1/ [R=301,L,NE,NE] 

#Adds a trailing slash 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*[^/])$ /$1/ [L,R=301,NE] 

#Removes HTMl-Extension and make URLs clean# 

#example.com/page will display the contents of example.com/page.html 
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule ^(.+?)/?$ $1.html [L] 
+0

감사합니다,하지만 작동하지 않습니다. :-(같은 오류 example.com/imprint는 말합니다 : 404 - example.com/imprint.html/ was foud. – hazelnut

+0

불행히도, 나를 위해 작동하지 않습니다. 변경 및 단지 404 : < – hazelnut

+0

내 대답을 시도하십시오 테스트 할 때 사용하고있는 URL을 알려주십시오. – anubhava

관련 문제