SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member tthmaz's Avatar
    Join Date
    Feb 2006
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Redirect 301 or RedirectRule?

    hi gurus,

    I'm trying to redirect pages from

    www.domain.com/category/product-name/reviews

    to

    www.domain.com/category/product-name/reviews/1

    How can I achive this? It looks easy at first sight and I had tried

    Redirect 301 /category/product-name/reviews /category/product-name/reviews/1

    but page still doesn't redirect

    btw, what tools can I use to test htaccess rules?

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

    IMHO, your redirect is not sufficiently different to not loop. Okay, at least that's what I suspect is your problem.

    Using mod_rewrite, you could add the /1 using:
    Code:
    RewriteEngine on
    RewriteRule category/product-name/reviews$ category/product-name/reviews/1 [R=301,L]
    The key to this NOT looping is the "end anchor," the $ after reviews in the regex. Since your redirection cannot be served by Apache, place this before your CMS's mod_rewrite block.

    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 Member tthmaz's Avatar
    Join Date
    Feb 2006
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks David, brilliant solution!

  4. #4
    SitePoint Member tthmaz's Avatar
    Join Date
    Feb 2006
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Came back with another similar situation and need some advice here.

    say i had a url /post-title-here/ which needs to be redirected to /blog/post-title-here and was achieved using:

    Redirect 301 /post-title-here/ /blog/post-title-here/

    Now that's all fine until coincidentally, there's a valid url such as

    /post-title-here/reviews

    that will fail to load the right page because of that Redirect

    So I then change the rule to Redirect 301 /post-title-here/$ /blog/post-title-here which will make /post-title-here/reviews load correctly.

    But then, /post-title-here/ doesn't get redirected to /blog/post-title-here/ anymore. Can someone show me some light?

    Thanks.

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

    While mod_alias is faster than mod_rewrite (because it's part of Apache's core), it lacks the power of mod_rewrite which is designed to use Apache's regex engine. Yes, RedirectMatch uses regex but it can't use conditionals.

    I'd either:

    1. Rename that directory with the reviews link

    OR

    2. Learn mod_rewrite to control the redirection (and provide an exclusion to the {whatever}/reviews URI).

    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


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
  •