Forum Moderators: phranque

Message Too Old, No Replies

Redirecting .co.uk to .com

         

Karma

4:17 pm on Aug 20, 2010 (gmt 0)

10+ Year Member



Hi :)

I have a .com and a .co.uk domains pointed at the same folder. The .com is the default but I bought the .co.uk just in case.

I'm currently redirecting the .co.uk to .com using the following htaccess instructions...

RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^mydomain\.com(:[0-9]+)?$
RewriteRule (.*) [mydomain.com...] [R=301,L]

This seems to work fine, but is this the correct way of doing it?

g1smd

5:25 pm on Aug 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



A single RewriteCond could replace the pair:

RewriteCond %{HTTP_HOST} !^(mydomain\.com)?$

jdMorgan

6:14 pm on Aug 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Note that this shorter version also corrects non-canonical FQDN-format and appended-port-number hostnames like "mydomain.com." or "mydomain.com:80" or "www.mydomain.com.:80" as well...

Jim

Karma

1:43 pm on Aug 21, 2010 (gmt 0)

10+ Year Member



Not working :/

Not sure if the shopping cart seo module instructions are conflicting?


RewriteEngine on
# Force .com
RewriteCond %{HTTP_HOST} !^(mydomainname\.com)?$
# URL rewriting rules
RewriteRule ^([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*)\.jpg$ /img/p/$1-$2$3.jpg [L,E]
RewriteRule ^([0-9]+)\-([0-9]+)/([_a-zA-Z0-9-]*)\.jpg$ /img/p/$1-$2.jpg [L,E]
RewriteRule ^([0-9]+)(\-[_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*)\.jpg$ /img/c/$1$2.jpg [L,E]
RewriteRule ^lang-([a-z]{2})/([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ /product.php?id_product=$3&isolang=$1$5 [L,E]
RewriteRule ^lang-([a-z]{2})/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ /product.php?id_product=$2&isolang=$1$4 [L,E]
RewriteRule ^lang-([a-z]{2})/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$ /category.php?id_category=$2&isolang=$1 [QSA,L,E]
RewriteRule ^([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ /product.php?id_product=$2$4 [L,E]
RewriteRule ^([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ /product.php?id_product=$1$3 [L,E]
RewriteRule ^([0-9]+)\-([a-zA-Z0-9-]*)(.*)$ /category.php?id_category=$1 [QSA,L,E]
RewriteRule ^content/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$ /cms.php?id_cms=$1 [QSA,L,E]
RewriteRule ^([0-9]+)__([a-zA-Z0-9-]*)(.*)$ /supplier.php?id_supplier=$1$3 [QSA,L,E]
RewriteRule ^([0-9]+)_([a-zA-Z0-9-]*)(.*)$ /manufacturer.php?id_manufacturer=$1$3 [QSA,L,E]
RewriteRule ^lang-([a-z]{2})/(.*)$ /$2?isolang=$1 [QSA,L,E]
# Catch 404 errors
ErrorDocument 404 /404.php

jdMorgan

2:11 pm on Aug 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You rather need your originally-posted RewriteRule following either your original two RewriteConds, or the suggested single RewriteCond...

Jim

Karma

2:57 pm on Aug 21, 2010 (gmt 0)

10+ Year Member



Thanks - working now :)

jdMorgan

3:09 pm on Aug 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good news!

Now look up the "[E]" flag in the mod_rewrite RewriteRule documentation at apache.org, and see if you can figure out why it appears in many of your rules, but with no declared variable name or value. If you have no intent to define and use a server variable, delete that "[E]" flag from your rewriterules.

Jim

Karma

3:33 pm on Aug 21, 2010 (gmt 0)

10+ Year Member



"regexp backreferences"?

My knowledge of rewrite rules is functional at best, will read up some more later and maybe start removing them.

Thanks again :)