2010-07-09 94 views
2

我有兩個域,格式爲foo.com和foo.net。目前,我有我的.htaccess到非www重定向到www以下幾點:重定向寄存的域名(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] 

不過,我想重定向在.NET結尾去.COM的網址,包括子域。 實例:

foo.net - > foo.com
www.foo.net - > www.foo.com
foo.net/bar - > foo.com/bar
sub.foo達網絡 - > 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

忽略了一個事實,這是迄今爲止,我曾經寫過最爲兇殘的重寫規則集,這令人吃驚,似乎照顧你現在有什麼,加上你想要的,在一個不錯的,緊湊的包。

讓我知道,如果你有任何問題:

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

當我取代我當前的規則與你的(內部500錯誤),但把我的當前設置後,沒有工作,有一個問題 - 當它重寫了一個匹配的URL,它會切斷URL的其餘部分(%{REQUEST_URI}),離開您www.foo.com – StormPooper 2010-07-11 09:34:46

+0

您是否有權訪問服務器的訪問和錯誤日​​志?它在我的測試服務器上工作正常(即使使用WordPress規則),所以我不知道爲什麼它會在您的環境中導致500錯誤。如果我們無法弄清楚,我可以寫出一個不太緊湊的解決方案,您可以使用它。 – 2010-07-11 09:56:33