0

Trying to 301 redirect

www.mydomain.com/product.php?view=cat&category=t-shirts

to

www.mydomain.com/t-shirts/

Please keep in mind that I have multiple variations of

product.php?view=cat&category=...

Also, old category reference maybe X; however, the new category reference might be Y. How is this done? Appreciate your help in advance.

Here is what my htaccess looks like right now

RewriteBase /
# RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([^/]*)/$ index\.php?pg=$1 [L]
RewriteRule ^([^/]*)/([^/]*)/$ index\.php?pg=$1&pid=$2 [L]
# RewriteRule . /index.php [L]

Redirect 301    /products.php?view=cat&mng=t-shirts http://www.mydomain.com/shirts/
Redirect 301    /products.php?view=cat&mng=shorts   http://www.mydomain.com/pants/
Redirect 301    /products.php?view=cat&mng=jeans    http://www.mydomain.com/pants/

Needless to say all my "Redirect 301"s are giving 404.

  • Maybe this can help you http://stackoverflow.com/questions/18805726/htaccess-rewrite-get-variables-w-301-redirect – daker Dec 12 '13 at 08:26
  • What do you mean by `Also, old category reference maybe X; however, the new category reference might be Y`? – anubhava Dec 12 '13 at 08:52
  • No that's not what I'm looking for. I had an old site that had www.mydomain.com/product.php?view=cat&category=t-shirts as its urls. The new site does not have the same structure. And I've change my category names. For example t-shirts is now shirts. – user3094390 Dec 12 '13 at 09:09

1 Answers1

0

I couldn't find any logic that would avoid the conflict in the "Rewrite" and "Redirect". Therefore, I utilized the php 301 redirect saving it in a file "products.php". In my script I did the following:

if (isset($_GET['mng']))
{ 
    switch ($_GET['mng'])
    {
        case 't-shirts':
            header("HTTP/1.1 301 Moved Permanently");
            header("Location: http://www.mydomain.com/shirts/");
            break;
        case 'shorts':
            header("HTTP/1.1 301 Moved Permanently");
            header("Location: http://www.mydomain.com/pants/");
            break;
        case 'jeans':
            header("HTTP/1.1 301 Moved Permanently");
            header("Location: http://www.mydomain.com/pants/");
            break;
    }
}

Sorry I didn't comment my php. Thank you for your input.