Help with RedirectMatch

Discussion in 'Apache' started by wonkyweb, Mar 8, 2007.

  1. #1
    Hi there - hoping somebody might be able to help me with this. I have a number of dynamic URLs that I need to rewrite to static pages and I'd like to do it with RedirectMatch if possible. Effectively, what I need to do is as follows:

    Right now I have this:

    http://www.mysite.com/article.aspx?articleID=144

    and I'd like to rewrite it to:

    http://www.mysite.com/category/new-article-name/

    I can't do any "fancy" remapping because all of the new URLs are completely different. It's going to me a manual process and I'm resigned to that. My old server was IIS (offline now) and the new is Apache. I've been messing with examples I found for days with no luck. The best I've managed to do is this:

    RedirectMatch /(.*)\.aspx$ http://www.mysite.com/

    ...but that obviously takes every aspx file and maps it over to the root of the domain.

    Can anyone help? I'm sure that I can get it sorted with one good example.

    Thanks so much.
     
    wonkyweb, Mar 8, 2007 IP
  2. TechEvangelist

    TechEvangelist Guest

    Messages:
    919
    Likes Received:
    140
    Best Answers:
    0
    Trophy Points:
    133
    #2
    Are you just trying to set up 301 redirects to capture the old URLs in the search engine indexes and redirect them to the new URLs?

    Because you are using an ID with the old URL and a name with the new URL, you will have to do a separate rule for each URL. I don't think there is a way to write a universal rule to do this. The following should work:

    redirect 301 /article.aspx?articleID=144 http://www.mysite.com/category/new-article-name/
    
    Code (markup):
    In order to get the search engines to change the old URLs in their index to the new ones you need to use a 301 redirect. You could also just let the old URLs generate error 404s and capture the user in a customized error 404 page. I think a lot depends upon whether you want to pass PageRank from the old URLs to the new and if you need to have them land on the same page as they did with the old URL.

    You may still run into problems if you don't get the order correct in .htaccess because it looks like you are going to rewrite the URL again using /new-article-name/ as the identifier to look up the article.
     
    TechEvangelist, Mar 8, 2007 IP
  3. wonkyweb

    wonkyweb Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi TE - thanks for the reply. I've tried that code already to no avail - even with an otherwise empty .htaccess file. It just goes 404 on me whenever ? or & is included in the URL to be redirected. I've been able to implement 301 redirects on plain old html files without issue...

    As I mentioned I have been able to get things working with RedirectMatch (which I would also use for 301s), but nothing beyond the general pattern matching in my original message. I understand that my new file naming choice means that I'll have no choice but to code all the redirects manually.

    And yes, the issue is mainly focused on the SEs.
     
    wonkyweb, Mar 8, 2007 IP
  4. TechEvangelist

    TechEvangelist Guest

    Messages:
    919
    Likes Received:
    140
    Best Answers:
    0
    Trophy Points:
    133
    #4
    Try escaping the question mark like this:
    redirect 301 /article.aspx\?articleID=144 http://www.mysite.com/category/new-article-name/
    Code (markup):
    See if that works.

    mod_rewrite can sometimes be strange because it doesn't give you much of a clue regarding the root of most problems.
     
    TechEvangelist, Mar 8, 2007 IP