SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    htaccess 301 redirect and regular expression problem

    Hello

    I am new here and was advised to join to see if anyone could help.

    I need to write a htaccess rule that redirects URLs that follow a certain string, to a new more appropriate URL.

    However there is a problem in that the pages i want to redirect also have subpages within them.

    e.g. I want to redirect this URL www.example.com/womens/designer-1-all to this URL www.example.com/womens/designer-1

    I then will replicate this for all designer pages which is an easy task and a simple rule to write. However on those '-all' pages are options that allow the user to filter products but creates brand new URLs like this:

    www.example.com/womens/designer-1-all/tops
    www.example.com/womens/designer-1-all/bags
    www.example.com/womens/designer-1-all/dresses

    This problem then replicates across all designer pages and there are too many to do this manually.

    How can i use reg ex's to write a rule that says when URL ends in '/tops' or '/bags' and is part of URL folder ending with '-all' then redirect to xxxx page?

    Thanks for any help in advance.

  2. #2
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Hi Keir_SL,

    Welcome to Sitepoint!

    Are the categories such as 'tops' and 'bags' parameter on your un re-written URL, like www.example.com/designer-1-all.html?cat='tops' or are these statically constructed links like www.example.com/designer-1-all/tops.html'?

    Steve
    ictus==""

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

    First, Welcome to SitePoint!

    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too. Come back with your attempt and I can walk you through what might be missing.

    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
  •