SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Zealot eeight's Avatar
    Join Date
    Oct 2006
    Location
    New York City
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy 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:

    Code:
    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.

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    E8,

    Why not
    Code:
    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 EVERYTHING 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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Zealot eeight's Avatar
    Join Date
    Oct 2006
    Location
    New York City
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Zealot eeight's Avatar
    Join Date
    Oct 2006
    Location
    New York City
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Zealot eeight's Avatar
    Join Date
    Oct 2006
    Location
    New York City
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DK,

    Gotcha--thanks for the lesson.

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

    Code:
    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

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    E8,

    OMG!
    Quote Originally Posted by DK
    [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).
    The lesson obviously didn't take! USE the Last flag to prevent everything being ANDed!
    Quote Originally Posted by eeight View Post
    DK,

    Gotcha--thanks for the lesson.

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

    Code:
    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
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  8. #8
    SitePoint Zealot eeight's Avatar
    Join Date
    Oct 2006
    Location
    New York City
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  9. #9
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    E8,

    No problem!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •