2010-07-09 5 views
2

foo.com 및 foo.net 형식의 두 도메인이 있습니다.파킹 된 도메인 (htaccess) 리디렉션

# Rewrite URL to force WWW 
    RewriteCond %{HTTP_HOST} ^[^.]*\.[^.]*$ 
    RewriteCond %{SERVER_PORT} !=443 
    RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

    RewriteCond %{HTTP_HOST} ^[^.]*\.[^.]*$ 
    RewriteCond %{SERVER_PORT} =443 
    RewriteRule^https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

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

    RewriteCond %{HTTP_HOST} ^www\.(.*\.[^.]*\.[^.]*)$ [NC] 
    RewriteCond %{SERVER_PORT} =443 
    RewriteRule^https://%1%{REQUEST_URI} [R=301,L] 

는 그러나, 나는 하위 도메인을 포함하여 .COM로 이동 그물로 끝나는 URL을 리디렉션 할 : 저는 현재 WWW에 www가 아닌 ​​리디렉션 내의 .htaccess에 다음 있습니다. 예 :

foo.net -> foo.com
www.foo.net -> www.foo.com
foo.net/bar -> foo.com/bar
sub.foo .NET -> sub.foo.com
sub.foo.net/bar -> sub.foo.com/bar

나는 다른 사이트에 이것을 가지고하는 데 사용하지만, 몇 년 전 내가 돈 더 이상 .htaccess가 없습니다. 아무도이 일을하는 쉬운 방법을 알고 있습니까?

편집 : 여기에 htaccess로의 나머지 부분입니다 :

# BEGIN WordPress 
# 
    RewriteEngine on 
# 
# Unless you have set a different RewriteBase preceding this point, 
# you may delete or comment-out the following RewriteBase directive 
# RewriteBase/
# 
# if this request is for "/" or has already been rewritten to WP 
    RewriteCond $1 ^(index\.php)?$ [OR] 
# or if request is for image, css, or js file 
    RewriteCond $1 \.(gif|jpg|png|php|ico|css|js)$ [NC,OR] 
# or if URL resolves to existing file 
    RewriteCond %{REQUEST_FILENAME} -f [OR] 
# or if URL resolves to existing directory 
    RewriteCond %{REQUEST_FILENAME} -d 
# then skip the rewrite to WP 
    RewriteRule ^(.*)$ - [S=1] 
# else rewrite the request to WP 
    RewriteRule . /index.php [L] 
# 
# END wordpress 

# Rewrite URL to force WWW 
    -(see top of post)- 

답변

1

여기까지 내가 쓴 가장 악마 재 작성 규칙 집합이라는 사실을 무시하고는,이 의외로 돌봐 보인다 당신이 현재 가지고있는 것의 더하기, 당신이 원하는 것, 멋진 컴팩트 한 패키지.

당신이 어떤 문제가 있다면 알려주세요 : 나는 당신 (내부 500 오류)하지만 내 현재 설정 후 배치와 함께 나의 현재의 룰을 교체 할 때

RewriteCond %{HTTPS} =on 
RewriteRule .* - [E=RW_HTTPS:s] 

RewriteCond %{HTTP_HOST}  ^www\.(.*\.[^.]*\.[^.]*)$ [NC,OR] 
RewriteCond www.%{HTTP_HOST} ^(www\.[^.]*\.[^.]*)$ 
RewriteRule .* - [E=RW_THOST:%1] 

RewriteCond %{ENV:RW_THOST} ^(.*)\.(net|com)$   [NC,OR] 
RewriteCond %{HTTP_HOST}  ^(.*)\.net$    [NC] 
RewriteRule .* http%{ENV:RW_HTTPS}://%1.com%{REQUEST_URI} [R=301,L] 
+0

그것은 작동하지 않았다 문제가있다 - 할 때마다 일치하는 URL을 다시 써서 나머지 URL (% {REQUEST_URI})을 차단하고 www.foo.com을 남깁니다. – StormPooper

+0

서버의 액세스 및 오류 로그에 액세스 할 수 있습니까? 내 테스트 서버 (WordPress 규칙 포함)에서도 정상적으로 작동하므로 사용자 환경에서 500 오류가 발생하는 이유는 무엇입니까? 우리가 그걸 알아낼 수 없다면 대신에 사용할 수있는 덜 조밀 한 솔루션을 쓸 수 있습니다. –

관련 문제