SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    rewrite url using regex in apache

    I have just moved a site from IIS to Apache and from asp to PHP however I don't want to have dead links all over the place I been reading about rewriting with regex but have not been able to make it work basically I had URLs that looked like this

    http://www.medialifemagazine.com/art...-this-fall.asp

    and now they are like this

    http://www.medialifemagazine.com/The...ity-this-fall/

    I have this so far but it does not work

    RewriteRule ^artman2/publish/([a-z]+) /([a-z]+)\.asp$

    this part is always the same

    http://www.medialifemagazine.com/artman2/publish/

    and this part always changes /The-coming-fall-season/For-Fox-a-newfound-stability-this-fall.asp

    any help is appreciated
    Do you get bothered because I do the same thing every day?
    Do you question why I do it?
    Then find something that you actually like doing!!!

    Stop thinking on what I do.

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

    Have you read the tutorial linked in my signature? There are two bits of sample code which would help, the first in defining character ranges and the second if replacing file extensions. To make a long story short, all you need is:
    Code:
    # .htaccess in DocumentRoot
    
    RewriteEngine on
    
    # Replace extension for directory/filename in artman2/publish directory
    # Note: Apache 2.x assumed
    RewriteRule ^artman2/publish/([-a-zA-Z]+)/([-a-zA-Z]+)\.asp$ artman2/publish/$1/$2.php [R=301,L]
    What you were missing was the leading - and uppercase characters in the character range definitions (and a redirection in your RewriteRule).

    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.

    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 Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    Amigo,

    Have you read the tutorial linked in my signature? There are two bits of sample code which would help, the first in defining character ranges and the second if replacing file extensions. To make a long story short, all you need is:
    Code:
    # .htaccess in DocumentRoot
    
    RewriteEngine on
    
    # Replace extension for directory/filename in artman2/publish directory
    # Note: Apache 2.x assumed
    RewriteRule ^artman2/publish/([-a-zA-Z]+)/([-a-zA-Z]+)\.asp$ artman2/publish/$1/$2.php [R=301,L]
    What you were missing was the leading - and uppercase characters in the character range definitions (and a redirection in your RewriteRule).

    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.

    Regards,

    DK
    I tried your rewrite and went through the link in your signature and still can't get it to work, I modified the rewrite you gave me as the structure is different but even trying yours the url does not change this is all I have right now in the htaccess file

    RewriteEngine On
    RewriteBase /
    RewriteRule ^artman2/publish/([-a-zA-Z]+)/([-a-zA-Z]+)\.asp$ index.php/$2/ [R=301,L]

    why would it not follow the rewrites?
    Do you get bothered because I do the same thing every day?
    Do you question why I do it?
    Then find something that you actually like doing!!!

    Stop thinking on what I do.

  4. #4
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Now I feel a little retarded, I guess I need to sleep a little more, I did not uncommented mod_rewrite, although reading that post in your signature did help and also the rewrite rule you helped me construct, thank you
    Do you get bothered because I do the same thing every day?
    Do you question why I do it?
    Then find something that you actually like doing!!!

    Stop thinking on what I do.

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


    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
  •