How to write redirect rule for a string in url with wildcard?

Discussion in 'Apache' started by shawnecstacy, Mar 5, 2009.

  1. #1
    shawnecstacy, Mar 5, 2009 IP
  2. starkman

    starkman Peon

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I am not really sure on how to do this with .htaccess, but if you want, you could do it with php :)
     
    starkman, Mar 6, 2009 IP
  3. shawnecstacy

    shawnecstacy Peon

    Messages:
    456
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I tried for whole night and finally got it.
    it will be

    RewriteEngine on
    Options +FollowSymLinks
    RewriteCond %{HTTP_HOST} ^digitalpoint.com$
    RewriteRule ^(.+)(world)(.+)\.html$ "http\:\/\/www\.digitalpoint\.com\/index\.php\?id\=world" [R=301,L]
    RewriteRule ^(world)(.+)\.html$ "http\:\/\/www\.digitalpoint\.com\/index\.php\?id\=world" [R=301,L]
    RewriteRule ^(.+)(world)\.html$ "http\:\/\/www\.digitalpoint\.com\/index\.php\?id\=world" [R=301,L]

    I have written three rules for abouve three urls but I think there is way of writing them all in one rule using the ? wildcard. I haven't tried it coz all of my urls have that particular keyword somewhere in the middle so i just needed the first rule. But i think it will be....

    RewriteRule ^((.+)?)(world)((.+)?)\.html$ "http\:\/\/www\.digitalpoint\.com\/index\.php\?id\=world" [R=301,L]
     
    shawnecstacy, Mar 7, 2009 IP