开发者

.htaccess causing endless loops, unable to rewrite .net to .com with a blog

开发者 https://www.devze.com 2023-01-30 22:38 出处:网络
I\'ve got a domain with the .com and .net and they both point to the same location. I need both the main site and the blog to map to one url because Google is slamming me for duplicate content.It\'s a

I've got a domain with the .com and .net and they both point to the same location. I need both the main site and the blog to map to one url because Google is slamming me for duplicate content. It's a PHP site and a Wordpress 开发者_JS百科Blog.

The ultimate goal is to rewrite each of these two sets to two distinct URL's. Is this possible? If it isn't possible can someone please recommend my closest option? Or maybe I should just eliminate the .net.

The .com is the primary site, and .net is parked to the same physical location.

otown411.com
www.otown411.com
otown411.net
www.otown411.net
--------------------
otown411.com   <--- **goal rewrite of any 4 above**


blog.otown411.com
blog.otown411.net
www.otown411.com/blog
www.otown411.net/blog
otown411.com/blog
otown411.net/blog
---------------------
blog.otown411.com  <--- goal rewrite from any six above

This is the closest I can get, it handles the top section fine, any attempts to get the blog section working result in endless loops:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{http_host} !^otown411\.com$ [NC]
RewriteRule ^(.*)$ http://otown411.com/$1 [R=301,NC,QSA,L]


This should do the trick:

Options +FollowSymLinks
RewriteEngine on
# Handle Blog first

RewriteCond %{HTTP_HOST} !^blog\.otown411\.com [NC] # check we're not where we want to be
RewriteCond %{HTTP_HOST} ^blog\. [NC,OR] # only if subdomo is blog OR...
RewriteCond %{REQUEST_URI} .*blog/.* [NC] # blog/ is in the URL
RewriteRule ^(blog/)?(.*?)$ http://blog.otown411.com/$2 [R=301,QSA,L]

# Now handle the rest

RewriteCond %{HTTP_HOST} !^blog\.otown411\.com [NC] # don't process for blog nor
RewriteCond %{HTTP_HOST} !^otown411\.com$ [NC] # if we're already on otown411.com
RewriteRule ^(.*)$ http://otown411.com/$1 [R=301,NC,QSA,L] 
0

精彩评论

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