2013-06-28 4 views
2

도메인 확장자 다시 쓰기 다음 URL이 다시 작성되도록 다음과 같이나는 여러 도메인 확장자를 가진 웹 사이트가

example.com 
example.de 
example.fr 
example.co.uk 

내가 .com 도메인으로 리디렉션하는 사람들 싶습니다을 :

example.de  -> http://www.example.com/?loc=de 
example.fr  -> http://www.example.com/?loc=fr 
www.example.co.uk -> http://www.example.com/?loc=uk 

그러나 URL example.(fr)/bla의 도메인 확장 부분을 선택하고 다시 쓰는 방법을 모르겠습니다. 나는 내가 더 많은 확장을 것을 구매하는 경우, 그래서 나는 등 httpd.conf 파일

을 업데이트 할 필요가 없습니다 것, 그것을하고 싶다 그러나 각 예 :

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

에 대한 특별한 경우를 만들 수 실현

모든 의견을 환영합니다!

답변

3

여러 도메인을 다루는 규칙을 만드는 것은 매우 간단합니다. 당신이 원하는 것을 달성하기 위해, 당신이 뭔가를 할 수 있습니다 :

RewriteCond %{HTTP_HOST} ^(www\.)?example\.(de|fr|co\.uk)$ 
RewriteRule .* http://www.example.com/?loc=%2 [R] 

그것은 example.de 소요 요청으로 example.com/~loc=de로 재 작성하고, .fr.co.uk에 대해서도 작동합니다. 그러나주의해야 할 점은 .co.uk 버전을 example.com/~loc=co.uk으로 다시 작성한다는 것입니다. 또한 새 도메인을 위해 수정해야합니다.

그래서, 여기에 좀 더 일반적인입니다 솔루션은, 그러나 당신이 원하는 무엇을 달성해야합니다

이제 조금 설명
RewriteCond %{HTTP_HOST} ^(www\.)?example\.(co\.)?(.*)$ 
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ 
RewriteRule .* http://example.com/?loc=%3 [R] 

:

첫 번째 RewriteCond이 같은 그것에 example 어떤 도메인과 일치 등 example.co.uk, www.example.de, www.example.xxx

RewriteCond 확실하게 그 HTTP_HOST 난 sn'texample.com 또는 www.example.com.

마지막으로 RewriteRule은 두 규칙과 일치하는 내용을 모두 다시 작성하고 도메인의 마지막 부분을 매개 변수로 마지막 부분에 고정합니다.

http://www.example.co.uk/ ->http://example.com/?loc=uk

http://www.example.de/ ->http://example.com/?loc=de

http://www.example.xxx/ ->

http://www.example.com/http://example.com/?loc=xxx 리디렉션하지 않습니다. 사용자가 http://www.example.de/some/path/index.php에 가면 위의 솔루션, 경로가 리디렉션하지 않을 것이라고


참고. 이 기능을 원하면 리디렉션에 경로를 포함해야합니다.

RewriteRule (.*) http://example.com/$1?loc=%3 [R] 
관련 문제