1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help with setting up the rewrite map

Discussion in 'Server Configuration and Hosting' started by Renegade, Jan 26, 2014.

  1. Renegade

    Renegade Well-Known Member

    Redirects are something I can't get my head around so naturally I am doing something wrong.

    I need to setup a redirect map and have done the following 3 things but still can't get it to work. What could I be doing wrong?

    Declare in httpd.conf
    Code:
    RewriteMap url_rewrite_map txt:/home/xyz/public_html/xf1.txt
    Placed a file with the following text in xf1.txt
    Code:
    /forum-abc/lets-play-10131.html /community/threads/lets-play.70898/
    Placed the following in .htaccess
    Code:
    RewriteCond ${url_rewrite_map:$1|NOT_FOUND} !NOT_FOUND
    RewriteRule ^(.*) http://www.site.com/${url_rewrite_map:$1} [R=301]
     
  2. TheBigK

    TheBigK Well-Known Member

    So did you get this working? Has it affected your site's performance in any way?
     
  3. Renegade

    Renegade Well-Known Member

    Yeah I got this working finally after some trial-error and redirect manuals. The key here is to get the rewrite rule correct. Rest is easy.

    No there is no noticeable impact on the performance. If at all it might have added a quarter of a second to the loading time.
     
  4. TheBigK

    TheBigK Well-Known Member

    Okay, so is this correct? -

    Code:
    RewriteCond ${url_rewrite_map:$1|NOT_FOUND} !NOT_FOUND
    RewriteRule ^(.*) http://www.site.com/${url_rewrite_map:$1} [R=301]
     
  5. Renegade

    Renegade Well-Known Member

    That is supposed to work according to the tutorials on the net but it did not. I had to modify it a bit to work. Basically I made the matching string more specific by adding the .html part in the end. And I put the entire URL in the rewrite map file so I removed the www.site.com part from the rewrite. The entire URL now comes from the map itself.
    Code:
    RewriteCond ${ErrorMap:$1|Unknown} !Unknown
    rewriterule ^(.*\.(html)) ${ErrorMap:$1|404} [R=301]
     

Share This Page