开发者

Redirect parked domain (htaccess)

I have two domains in the format of foo.com and foo.net. I currently have the following in my .htaccess to redirect non-www to www:

# Rewrite URL t开发者_JAVA百科o 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]

However, I want to redirect URLs ending in .net to go to .com, including the subdomains. Examples:

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

I used to have this on another site, but it was years ago and I don't have the .htaccess anymore. Does anybody know an easy way of doing this?

Edit: Here is the rest of the .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)-


Ignoring the fact that this is by far the most devilish rewrite ruleset that I've ever written, this surprisingly seems to take care of what you currently have, plus what you want, in a nice, compact package.

Let me know if you have any problems with it:

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]


To Redirect Parked domain to main website domain with specific URL Try The following code on your htacess file :

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^parked-domain.com [OR]
RewriteCond %{HTTP_HOST} ^www.parked-domain.com
RewriteRule ^(.*)$ https://main-domain.com/custom-url [L,R=301]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜