1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

index.htm-301 redirection

Discussion in 'Apache' started by seckin, Sep 20, 2005.

  1. #1
    I need to redirect my index.htm permanently to index.htm?id=1
    I tried this line in the .htaccess file:
    RewriteRule ^index.htm$ http://www.site.com/index.htm?id=1 [R=301,L]
    Didn't work. I also need www.mysite.com always redirect to www.mysite.com/index.htm?id=1
    Can someone help about these two questions of mine? Thank you in advance.

    (id=1 is not a functional tag actually.It's been months in adsense and my index page only gets PSA's. I tried every possible way, but can't get any relevant ads if I don't use a tag with index.htm and index.php. Interesting but it happens.)
     
    seckin, Sep 20, 2005 IP
  2. johnt

    johnt Peon

    Messages:
    178
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you need to add
    RewriteCond %{QUERY_STRING} ! id=1
    Code (markup):
    before your RewriteRule, otherwise it will redirect even when you have id=1 specified
     
    johnt, Sep 21, 2005 IP
  3. seckin

    seckin Peon

    Messages:
    108
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Johnt, I added
    RewriteCond %{QUERY_STRING} ! id=1
    
    RewriteRule ^index.htm$ http://www.site.com/index.htm?id=1 [R=301,L]
    
    
    Code (markup):
    But I get an Internal Server Error.
     
    seckin, Sep 21, 2005 IP
  4. johnt

    johnt Peon

    Messages:
    178
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ah, yes. There shouldn't be a space between the ! and id=1, so it should be
    RewriteEngine on
    RewriteCond %{QUERY_STRING} !id=1
    RewriteRule index.htm index.htm?id=1 [R=301,L]
    
    Code (markup):
    cheers

    John
     
    johnt, Sep 21, 2005 IP
  5. GRIM

    GRIM Prominent Member

    Messages:
    12,638
    Likes Received:
    733
    Best Answers:
    0
    Trophy Points:
    360
    #5
    It's early in the morning so maybe I'm missing something here but if using .htaccess why not simply use the following much easier format which has always worked for me.

    Redirect 301 /index.htm http://www.domain.com/index.htm?id=1

    If it works great, if not I need more coffee before I read or respond to posts :)
     
    GRIM, Sep 21, 2005 IP
  6. seckin

    seckin Peon

    Messages:
    108
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thank you John, it's ok now:) Tried the same redirect with index.php too(pointing to index.php?id=1) but there are other queries in the script using index.php(like index.php?action=sc&id=2, etc.). The redirect gets these queries into infinite loops.
     
    seckin, Sep 21, 2005 IP
  7. johnt

    johnt Peon

    Messages:
    178
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If there aren't too many different variables which get passed to index.php, you could just have a separate RewriteCond for each one, only doing the rewrite if none of them are there, e.g.
    RewriteCond %{QUERY_STRING} !action
    RewriteCond %{QUERY_STRING} !id
    RewriteRule index.php index.php?id=1 [R=301, L]
    Code (markup):
    John
     
    johnt, Sep 22, 2005 IP
  8. GRIM

    GRIM Prominent Member

    Messages:
    12,638
    Likes Received:
    733
    Best Answers:
    0
    Trophy Points:
    360
    #8
    Didn't take into account using the index for other queries, guess I needed more coffee :)
     
    GRIM, Sep 22, 2005 IP
  9. seckin

    seckin Peon

    Messages:
    108
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    If you tell me how to get out of this, I'll make espresso for you myself, hrblcantra:)
     
    seckin, Sep 22, 2005 IP