New Domain, Same Host (Ripping out my hair!)

I changed domain names (eeight.com -> gagcartoons.com) and thought the 301 would be a piece of cake. Not so. Would greatly appreciate any help.

Here’s what I currently have:

RewriteCond %{http_host} !^www\\.gagcartoons\\.com$ [nc]
RewriteRule ^(.*)$ http://www.gagcartoons.com/$1 [r=301,nc]

This does redirect eeight.com to gagcartoons.com, but it doesn’t redirect eeight.com/cartoons/ to gagcartoons.com/cartoons/ (gives 404 error). If it makes any difference, “/cartoons/” isn’t an actual folder, but just a mod_rewrite. How can I make it redirect all the subfolders to the new domain?

PS - I have searched for and tried several methods (like this one), but none seem to work. Some even gave a “Redirect Loop” error.

E8,

Why not

RewriteEngine on
RewriteCond %{HTTP_HOST} eeight\\.com$ [NC]
RewriteRule .? http://www.gagcartoons.com%{REQUEST_URI} [R=301,L]

Aside from looking for the OLD domain to redirect to the new domain, I’ve used the {REQUEST_URI} variable rather than capture it again with the :kaioken: EVERYTHING :kaioken: atom

AND

replaced the No Case flag with the Last flag in the redirection. Why bother using it there with . matched EVERYTHING … AND you need to end the mod_rewrite block statement?

Regards,

DK

Thanks dklynn, I will try that (at work now and cannot access .htaccess file).

What do you mean by “end the mod_rewrite block statement”? Is that what the “L” does?

Thanks again for your help.

Unfortunately it’s still not working. Just as before, it redirects eeight.com to gagcartoons.com, but not eeight.com/cartoons/ to gagcartoons.com/cartoons/. Any clue what’s wrong?

Thanks very much for your help.

E8,

[L] is the Last flag. That’s the same thing as ; and/or } in typical programming languages. Unfortunately, mod_rewrite does not require it in order to function (it ANDs that block with the following block statement without the Last flag).

If that’s not working for you, you need to show ALL your .htaccess file as there is no reason for it not to work with what is shown.

Regards,

DK

DK,

Gotcha–thanks for the lesson.

Here’s the full .htaccess file. I hope it helps to see what’s wrong:


ErrorDocument 404 /404.php

RewriteEngine On

Options -Indexes

RewriteCond %{HTTP_HOST} www\\.eeight\\.com$ [NC]
RewriteRule .? http://www.gagcartoons.com%{REQUEST_URI} [R=301,L]

RewriteRule ^rss$ /rss/ [R]
RewriteRule ^rss/$ /rss.xml

RewriteRule ^tutorials$ /cartoon-tutorials/ [R]
RewriteRule ^tutorials/([A-Za-z0-9-]+)$ /cartoon-tutorials/ [R]
RewriteRule ^tutorials/$ /cartoon-tutorials/ [R]

RewriteRule ^tutorials/([A-Za-z0-9-]+)/$ /cartoon-tutorials/ [R]
RewriteRule ^tutorials/([A-Za-z0-9-]+)/([0-9]+)$ /cartoon-tutorials/ [R]
RewriteRule ^tutorials/([A-Za-z0-9-]+)/([0-9]+)/$ /cartoon-tutorials/ [R]

RewriteRule ^cartoon-tutorials/([A-Za-z0-9-]+)$ /cartoon-tutorials/$1/ [R]
RewriteRule ^cartoon-tutorials/([A-Za-z0-9-]+)/$ /cartoon-tutorial.php?url=$1

RewriteRule ^cartoons/page-([0-9]+)$ /cartoons/page-$1/ [R]
RewriteRule ^cartoons/page-([0-9]+)/$ /cartoons.php?pageno=$1

RewriteRule ^cartoons/([0-9]+)$ /cartoons/$1/ [R]
RewriteRule ^cartoons/([0-9]+)/$ /cartoon.php?id=$1

RewriteRule ^cartoons/buy$ /cartoons/buy/ [R]
RewriteRule ^cartoons/buy/$ /buy.php

RewriteRule ^cartoons/tags$ /cartoons/$1/ [R]
RewriteRule ^cartoons/tags/$ /cartoons-tags.php

RewriteRule ^cartoons/([A-Za-z-]+)$ /cartoons/$1/ [R]
RewriteRule ^cartoons/([A-Za-z-]+)/$ /cartoons.php?tag=$1

RewriteRule ^cartoons/([A-Za-z]+)/([0-9]+)$ /cartoons/$2/ [R]
RewriteRule ^cartoons/([A-Za-z]+)/([0-9]+)/$ /cartoons/$2/

RewriteRule ^cartoons/([A-Za-z-]+)/page-([0-9]+)$ /cartoons/$1/page-$2/ [R]
RewriteRule ^cartoons/([A-Za-z-]+)/page-([0-9]+)/$ /cartoons.php?tag=$1&pageno=$2

RewriteRule ^cartoons$ /cartoons/ [R]
RewriteRule ^cartoons/$ /cartoons.php

RewriteRule ^admin$ /admin/ [R]
RewriteRule ^admin/$ /admin/admin.php

RewriteRule ^([A-Za-z0-9-]+)$ /$1/ [R]
RewriteRule ^([A-Za-z0-9-]+)/$ /$1.php

E8,

OMG! :eyes:

The lesson obviously didn’t take! USE the Last flag to prevent everything being ANDed!

Without seeing your test URI, no telling what will happen (other than NOTHING) past the first redirection.

Moreover, the / in the redirections CAN (not necessarily will) cause problems as that can be interpreted by Apache as dealing with the physical root rather than DocumentRoot.

Regards,

DK

The thing I love/hate about programming/coding is that, some times, the biggest headaches are caused by the smallest mistakes.

I went into my cPanel and changed the old domain (eeight.com) from an “Add-on Domain” to a “Parked Domain.” Now the code you gave me works like a charm. Thanks very much for your continued help!

E8,

No problem!

Regards,

DK