FAQ: mod_rewrite, 301 redirects, and optimizing Apache.

Discussion in 'Apache' started by Nintendo, Jul 30, 2005.

  1. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #61
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^tones/([^.]+)/([^.]+).html$ polyphonic_tones.php?mmchar22_1=$1&mmstart22_1=$2&mmsection22_1=&mmphonetype22_1=&mmmoreinfo22_1=&mmpart22_1=&mmsearch22_1=&mmstype22_1=&mmcat22_1=&mmcountry22_1= [L]

    tones/whatever/whatever.html

    That's if only the mmchar22_1=Y&mmstart22_1=1 always have something after the =
     
    Nintendo, Sep 26, 2005 IP
  2. Imran

    Imran Notable Member

    Messages:
    2,340
    Likes Received:
    190
    Best Answers:
    0
    Trophy Points:
    230
    #62
    Thanks,
    I did that still the same thing, no change in the url!
    Im I doing somthing wrong?
    www. smsjunky .com this is the url that m trying for mod rewrite!
    Thanks again!
     
    Imran, Sep 26, 2005 IP
  3. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #63
    Nintendo, Sep 26, 2005 IP
  4. Imran

    Imran Notable Member

    Messages:
    2,340
    Likes Received:
    190
    Best Answers:
    0
    Trophy Points:
    230
    #64
    Yes Its working Thanks, I will change the Image code!
    What should I do for this url?
    http://www. smsjunky. com/polyphoni...&mmstart22_1=1&mmsection22_1=&mmphonetype22_1
    =&mmmoreinfo22_1=0&mmpart22_1=&mmsearch22_1=&mmstype22_1=&mmcat22_1=&mmcountry22_1=#
    # at the end!
    hmm Its giving me error since everything it is now looking at /tones/y/ dont know what to do with that one!
    How can I have a mod rewrite for this url?
    http:// bollyhome. com/component/option,com_frontpage/Itemid,1/limit,4/limitstart,4/
    Thanks Nintendo you are doing a great help!
    Thanks!
     
    Imran, Sep 26, 2005 IP
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #65
    I'm not sure if # can change. That's a comment line in .htaccess along with perl.

    http://www.smsjunky.com/tones/y/uk_top_40_polyphonic.php

    type of URLs also need a line added to .htaccess. Post the original URL for those links and I can post the code.
    Post the php URL to that.
     
    Nintendo, Sep 26, 2005 IP
  6. Imran

    Imran Notable Member

    Messages:
    2,340
    Likes Received:
    190
    Best Answers:
    0
    Trophy Points:
    230
    #66
    Imran, Sep 26, 2005 IP
  7. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #67
    If you did for example

    RewriteRule ^tones/([^.]+)/([^.]+)/([^.]+)/([^.]+)/([^.]+)/([^.]+)/([^.]+)/([^.]+)/([^.]+)/([^.]+).html$ polyphonic_tones.php?mmchar22_1=$1&mmstart22_1=$2&mmsection22_1=$3&mmphonetype22_1=$4&mmmoreinfo22_1=$5&mmpart22_1=$6&mmsearch22_1=$7&mmstype22_1=$8&mmcat22_1=$9&mmcountry22_1=$10 [L]

    you would end up with domain.com/tones/y/1/////////

    So if those don't ever have anything in the URL just take them out of the links if you can.

    http://www.smsjunky.com/phone_compatibilty.php
    to
    http://www.smsjunky.com/phone_compatibilty.html

    RewriteRule ^([^.]+).html$ $1.php [L]

    Should cover them all. if it messes up some URLs,

    RewriteRule ^phone_compatibilty.html$ phone_compatibilty.php [L]

    for each file.
     
    Nintendo, Sep 26, 2005 IP
  8. Imran

    Imran Notable Member

    Messages:
    2,340
    Likes Received:
    190
    Best Answers:
    0
    Trophy Points:
    230
    #68
    Imran, Sep 27, 2005 IP
  9. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #69
    In the script, search for mmsearch1_1, mmpart1_1 and so on and take the extra pert of the URLs out. mod_rewrite can't take them out of the links! Only the script can by being changed.
     
    Nintendo, Sep 27, 2005 IP
  10. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #70
    The FAQ has been updated with info from replies added to it. And I've placed it in the Public Domain. If you know info that's missing, you can add to the FAQ. It uses wiki.
     
    Nintendo, Oct 6, 2005 IP
  11. expat

    expat Stranger from a far land

    Messages:
    873
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #71
    great,

    one litle thing a lot of people fall flat on is when rewriting directory style e.g. domain.com/a/b/b/c a lot of people miss their pics and graphs, due to the fact that these have not been made absolute links or been coded apropriately.

    Thought I mention it
    Expat
     
    expat, Oct 6, 2005 IP
  12. keral82

    keral82 Banned

    Messages:
    781
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #72
    keral82, Oct 7, 2005 IP
  13. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #73
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^links/([^.]+)/([^.]+).html$ links/index.php?ax=list&sub=$1&cat_id=$2 [L]

    domain.com/.htaccess

    domain.com/links/WHATEVER/WHATEVER.html
     
    Nintendo, Oct 7, 2005 IP
  14. keral82

    keral82 Banned

    Messages:
    781
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #74
    Yeah i substituted it for my domain name at 'domain.com'

    And also substituted 'WHATEVER/WHATEVER.html'
    with list/page1.html

    Is it true???

    Or am i missing something??
     
    keral82, Oct 8, 2005 IP
  15. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #75
    Nintendo, Oct 8, 2005 IP
  16. keral82

    keral82 Banned

    Messages:
    781
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #76
    This also giving errors Okay let it go. I will try some other script which has mod rewrite documentation with it. Thanks anyway for all your help.
     
    keral82, Oct 8, 2005 IP
  17. expat

    expat Stranger from a far land

    Messages:
    873
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #77
    ... I love these .. gives some kind of error.....

    what error?

    Martin
     
    expat, Oct 8, 2005 IP
  18. Imran

    Imran Notable Member

    Messages:
    2,340
    Likes Received:
    190
    Best Answers:
    0
    Trophy Points:
    230
    #78
    Im stuck here with this url
    http:// domain. .com /search.html?author=&category=&keyword=&number=&x=28&y=6
    n i used this re write code!
    search.html?author=$1&category=$2&keyword=$3&number=$4&x=$5&y=$6 and its not working any help please?
     
    Imran, Oct 10, 2005 IP
  19. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #79
    Post the complete .htaccess file code you got. The left part before the first $ tells the server how you want it. That part tells it where the file is at.
     
    Nintendo, Oct 10, 2005 IP
  20. Imran

    Imran Notable Member

    Messages:
    2,340
    Likes Received:
    190
    Best Answers:
    0
    Trophy Points:
    230
    #80
    # 301 redirects...
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.xr-designs\.com
    RewriteRule (.*) http://www.xr-designs.com/$1 [R=301,L]
    RewriteRule ^SeachedResults.html$ search.html?author=$1&category=$2&keyword=$3&number=$4&x=$5&y=$6 [L,NS,NC,QSA]

    ErrorDocument 404 http://www.xr-designs.com

    hope this helps!
     
    Imran, Oct 10, 2005 IP