2013-05-03 4 views
0

내 .htaccess에 슬래시 및 비 슬래시 URL을 내 홈페이지에서 .html 모든 URL로 리다이렉트하기 위해 일부 코드를 추가하려고합니다..htaccess 301 비 슬래시 도메인 리디렉션 및 .html로 도메인 슬래시

예를 www.mydomain.com/cat/를 들어

및 www.mydomain.com/cat~~HEAD=V은 내에 다음을 추가하기 위해 내가 관리해야

www.mydomain.com/cat.html로 리디렉션합니다. 바로 이곳의 www.mydomain.com/cat.html에 www.mydomain.com/cat을 리디렉션하지만 htaccess로는 슬래시 버전이 .html 페이지

RewriteCond %{REQUEST_URI} !\.[^./]+$ 
RewriteCond %{REQUEST_URI} !(.*)/$ 
RewriteRule ^(.*)$ http://mydomain.com/$1.html [R=301,L] 

내 전체 htaccess로 리디렉션하는 방법에 약간의 도움이 필요합니다 누군가가 위의 관점에서 어떻게보아야하는지에 대한 제안이 있다면 크게 좋아할 것입니다. 이 해결

Options +FollowSymlinks 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^xxx.xxx.xxx.xx [nc,or] 
RewriteCond %{HTTP_HOST} ^mydomain.com [NC] 
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301] 

RewriteCond %{THE_REQUEST} ^.*/index.php 
RewriteRule ^(.*)index.php$ /$1 [R=301,L] 


RewriteCond %{REQUEST_URI} !\.[^./]+$ 
RewriteCond %{REQUEST_URI} !(.*)/$ 
RewriteRule ^(.*)$ http://mydomain.com/$1.html [R=301,L] 


DirectoryIndex index.html index.php 

<IfModule mod_rewrite.c> 
RewriteEngine on 
# Pleas note that RewriteBase setting is obsolete use it only in case you experience some problems with SEO addon. 
# Some hostings require RewriteBase to be uncommented 
# Example: 
# Your store url is http://www.yourcompany.com/store/cart 
# So "RewriteBase" should be: 
# RewriteBase /store/cart 
# RewriteBase/
RewriteCond %{REQUEST_FILENAME} !\.(png|gif|ico|swf|jpe?g|js|css)$ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . index.php?sef_rewrite=1 [L,QSA] 

</IfModule> 

:

RewriteCond %{REQUEST_URI} ^(.+)/$ 
RewriteRule ^(.+)/$ /$1 [R=301,L] 

답변

0

별도의 규칙이 당신을 위해 작동하는 것 같군,하지만 난 당신이 옵션 슬래시로, 하나의 규칙으로 단순화 할 수 있다고 생각 : 은 그냥 덧붙였다. 규칙은 슬래시를 no-slash로 리디렉션 한 다음 다시 .html로 리디렉션합니다. 하나의 규칙으로 하나의 리디렉션 만 가질 수 있습니다.

이것은 파일이나 폴더가 아닌지를 확인하는 표준 RewriteCond를 가지고 있으므로 이미있는 경우 .html을 리디렉션하지 않습니다. 그런 다음 ReweriteRule의 \?은 선택적 슬래시입니다. 이 도메인의 모든 경우

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/?$ http://mydomain.com/$1.html [R=301,L] 

, 당신은 결과에서 생략 할 수 있습니다 :

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

, 이것은 당신이에 의미 여부, 잡아 하위 작동합니다 유의하십시오. 예 : www.mydomain.com/animals/cat/은 www.mydomain.com/animals/cat.html로 리디렉션됩니다.