Forum Moderators: phranque

Message Too Old, No Replies

Domain change need to update .htaccess for SEO

Domain change need to update .htaccess for SEO

         

dirtymonkey

4:53 pm on Jan 30, 2010 (gmt 0)

10+ Year Member



Hi Jim, I hope your well.

You kindly helped be a couple of time before with code below:

########## Begin - Rewrite rules to enhance SEO SEF
#
# Externally redirect to canonical hostname, preserving the original
# request's http/https protocol, but excluding xmlrpc requests.
RewriteCond $1 !xmlrpc [NC]
RewriteCond %{HTTP_HOST} ^(originaldomain\.org|www\.originaldomain\.org(\.|\.?[0-9]+)$) [NC]
RewriteCond %{SERVER_PORT}>s ^(443>(s)|80>s)$
RewriteRule ^(.*)$ http%2://www.originaldomain.org/$1 [R=301,L]
#
########## End - Rewrite rules to enhance SEO SEF

The website is now changing names and has a new domain name pointing to the same site.

How do I update the code to point all requests for originaldomain to newdomain keeping the www rewrite intact?

Thanks in advance.

jdMorgan

12:28 pm on Jan 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What have you tried so far?

Jim

dirtymonkey

3:43 pm on Jan 31, 2010 (gmt 0)

10+ Year Member



Hi Jim,

I don't really know what I'm doing... I tried something yesterday which didn't work, tried this today and it seems to be working! ;)

########## Begin - Rewrite rules to enhance SEO SEF
#
# Externally redirect to canonical hostname, preserving the original
# request's http/https protocol, but excluding xmlrpc requests.
RewriteCond $1 !xmlrpc [NC]
RewriteCond %{HTTP_HOST} ^(origdomain\.org|www\.origdomain\.org|newdomain\.org|www\.newdomain\.org(\.|\.?[0-9]+)$) [NC]
RewriteCond %{SERVER_PORT}>s ^(443>(s)|80>s)$
RewriteRule ^(.*)$ http%2://www.newdomain.org/$1 [R=301,L]
#
########## End - Rewrite rules to enhance SEO SEF

Is this correct? can I optimise?

DM.

jdMorgan

4:22 pm on Jan 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, well our purpose here [webmasterworld.com] is to help you learn what you are doing, not to write your code... Any mod_rewrite-code-related question posted in this forum gets the same response that you did if there is no accompanying code to discuss.

That code looks basically OK, but you can shorten it up a bit -- specifically the "origdomain" and "www.origdomain" subpattern in the second RewriteCond:


# Redirect requests for all "origdomain.org" variants, non-www "newdomain.org"
# variants, and any www.newdomain.org variants which have a FQDN indicator and/or
# an appended port number to "www.newdomain.org".
RewriteCond %{HTTP_HOST} ^((www\.)?origdomain\.org|newdomain\.org|www\.newdomain\.org(\.|\.?[0-9]+)$) [NC,OR]

This makes the "www." optional on the "olddomain" subpattern without requiring an additional in-line 'OR'.

But let me ask this: This rule will not redirect xmlrpc requests for *either* domain. Is that what you want?

Jim

dirtymonkey

4:57 pm on Jan 31, 2010 (gmt 0)

10+ Year Member



Hi Jim,

I understand, my fault for not including full info in the first place.
Unfortunately the optimised code does not work for me...

Regarding redirecting xmlrpc requests, If I recall correctly Joomla didn't like URL's inc. www. etc. so happy to exclude it from all rewrites for now.

DM.