SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Mod rewrite

  1. #1
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mod rewrite

    Hi

    I have a website with the following url rewrite set

    Code:
    RewriteRule ^Cat-(.*)-(.*).html$ section.php?cat_name=$1&cat=$2
    I'd like to change the URLs from

    to

    I can change the rewrite rule to

    Code:
    RewriteRule ^L1-(.*)-(.*).html$ section.php?cat_name=$1&cat=$2
    But is there a way I can redirect any pages listed in search engines so that

    is redirected

    Thanks

  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)
    rt,

    Yes, that's a simple replacement redirection. See the sample code in my signature's tutorial.

    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
    Join Date
    May 2005
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it. Thanks DK

  4. #4
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awwww

    I did have it. But I have returned a few weeks later to admire my break through and I can find no evidence of the work I did.
    What a bad trip!

    I think I did something like this but it isn't right.
    RewriteEngine on
    RewriteRule ^L1-(.*)-(.*).html$ Cat-$1-$2.html [N,L]

    Anybody help me?

  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)
    rt,

    Based on your sample characters (lowercase for $1 and digits for $2), I'd use:

    Code:
    RewriteEngine on
    RewriteRule ^L1-([a-z]+)-([0-9]+)\.html$ section.php?cat_name=$1&cat=$2 [L]
    When you are in a position to specify the characters used in your links, use them in the mod_rewrite code, too. It may be a small security issue to you but it would make hacking much easier for someone trying to break into your website. Besides, the inappropriate use of the EVERYTHING atom is the first indication that the coder has no idea what he/she is doing (and generally results in looping code).

    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
    Join Date
    May 2005
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks DK

    I appreciate the heads up on the security gap. But $1 is a often a mix of Uppercase and lower case so would that make
    ([a-z]+)
    this
    ([A-Z]+)
    As important as the security issue is your suggestion doesn't work for the redirect I need.

    For example I need:

    http://www.myOLDdomain.com/Cat-Harle..._Parts-39.html

    to go to

    http://www.myNEWdomain.co.uk/L1-Harl..._Parts-39.html


    I.E. the 'Cat' in the old domain becomes a 'L1' in the new domain.

    Thanks for getting back so promptly


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
  •