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
    #321
    Post an example of the original URL, and how you want it. It might be possible to need less than 10. I'm not sure why it stops working at 10.
     
    Nintendo, Jun 19, 2006 IP
  2. trung

    trung Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #322
    Example of URL:
    http://mdev.goo-net.com/cgi-bin/goo_mobile/NEW/search/search_car_w.cgi?disp_mode=car_list&brand_cd=1010&carrier=i-mode&country_cd=10&uri_flag=1

    In my .htaccess file:
    RewriteRule ^search_car/(.*)--(.*)/(.*)--(.*)/(.*)--(.*)/(.*)--(.*)/(.*)--(.*)\.html$ /cgi-bin/goo_mobile/NEW/search_static/
    search_car_w.cgi?$1=$2&$3=$4&$5=$6&$7=$8&$9=$10 [L]

    Thank Nintendo :)
     
    trung, Jun 19, 2006 IP
  3. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #323
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^search_car/disp_mode\-\-([^.]+)/brand_cd\-\-([^.]+)/carrier\-\-([^.]+)/country_cd\-\-([^.]+)/uri_flag\-\-([^.]+)\.html$ /cgi-bin/goo_mobile/NEW/search_static/search_car_w.cgi?disp_mode=$1&brand_cd=$2&carrier=$3&country_cd=$4&uri_flag=$5 [L]

    if you can have the brand_cd, carrier and other stuff in the URL.
     
    Nintendo, Jun 19, 2006 IP
  4. trung

    trung Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #324
    Sorry, the right URL (the Japanese page):

    http://m.goo-net.com/cgi-bin/goo_mobile/NEW/search/search_car_w.cgi?disp_mode=car_list&brand_cd=1010&carrier=i-mode&country_cd=10&uri_flag=1
     
    trung, Jun 19, 2006 IP
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #325
    The sub-domain part isn't needed in the code.
     
    Nintendo, Jun 19, 2006 IP
  6. trung

    trung Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #326
    Thank Nintendo,

    If the order of parametter is fixed, your rule is OK.
    But in my program, this order can be changed. I mean:
    Ex:
    http://m.goo-net.com/cgi-bin/goo_mobile/NEW/search/search_car_w.cgi?disp_mode=car_list&brand_cd=1010&carrier=i-mode&country_cd=10&uri_flag=1
    http://m.goo-net.com/cgi-bin/goo_mobile/NEW/search/search_car_w.cgi?disp_mode=car_list&brand_cd=1010&country_cd=10&carrier=i-mode&uri_flag=1

    The result are the same?
     
    trung, Jun 19, 2006 IP
  7. trung

    trung Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #327
    Thank Nintendo,

    If the order of parametter is fixed, your rule is OK.
    But in my program, this order can be changed. I mean:
    Ex:
    http://m.goo-net.com/cgi-bin/goo_mobile/NEW/search/search_car_w.cgi?disp_mode=car_list&brand_cd=1010&carrier=i-mode&country_cd=10&uri_flag=1
    http://m.goo-net.com/cgi-bin/goo_mobile/NEW/search/search_car_w.cgi?disp_mode=car_list&brand_cd=1010&country_cd=10&carrier=i-mode&uri_flag=1

    The result are the same.

    Can you give me other rule? Thank a lot.
     
    trung, Jun 19, 2006 IP
  8. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #328
    RewriteRule ^search_car/disp_mode\-\-([^.]+)/brand_cd\-\-([^.]+)/country_cd\-\-([^.]+)/carrier\-\-([^.]+)/uri_flag\-\-([^.]+)\.html$ /cgi-bin/goo_mobile/NEW/search_static/search_car_w.cgi?disp_mode=$1&brand_cd=$2&country_cd=$3&carrier=$4&uri_flag=$5 [L]
     
    Nintendo, Jun 19, 2006 IP
  9. trung

    trung Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #329
    Thank a lot. But how in this cace?

    http://m.goo-net.com/cgi-bin/goo_mobile/NEW/search/disp_photo_w.cgi?brand_cd=2015&car_cd=20151501&grade_cd=50&country_cd=20&head=18&carrier=i-mode&autos_id=10030134&uid=NULLGWDOCOMO&model_year=2005&model_month=10&angle=op&uri_flag=1

    I can't get value from $10.
     
    trung, Jun 19, 2006 IP
  10. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #330
    This only have five. I don't know why it doesn't work with 10 or more.
     
    Nintendo, Jun 19, 2006 IP
  11. trung

    trung Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #331
    Ofcourse I have other rule in this case (but can't get value from $10):
    RewriteRule ^disp_photo/(.*)--(.*)/(.*)--(.*)/(.*)--(.*)/(.*)--(.*)/(.*)--(.*)/(.*)--(.*)/(.*)--(.*)/(.*)--(.*)/(.*)--(.*)/(.
    *)--(.*)/(.*)--(.*)/(.*)--(.*)\.html$ /cgi-bin/goo_mobile/NEW/search_static/disp_photo_w.cgi?$1=$2&$3=$4&$5=$6&$7=$8&$9=$10&$
    11=$12&$13=$14&$15=$16&$17=$18&$19=$20&$21=$22&$23=$24 [L]
     
    trung, Jun 19, 2006 IP
  12. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #332
    Oh no!!! Make a post at
    webmasterworld.com/forum92/
    they might know how to get it to 10 and above.
     
    Nintendo, Jun 19, 2006 IP
    The Webmaster likes this.
  13. trung

    trung Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #333
    Thank Nintendo.
     
    trung, Jun 19, 2006 IP
  14. The Webmaster

    The Webmaster IdeasOfOne

    Messages:
    9,516
    Likes Received:
    718
    Best Answers:
    0
    Trophy Points:
    360
    #334
    The Webmaster, Jun 23, 2006 IP
  15. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #335
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^dir/([^.]+)/([^.]+)\.html$ dir/index.php?act=$1&id=$2 [L]

    or

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /dir/
    RewriteRule ^([^.]+)/([^.]+)\.html$ index.php?act=$1&id=$2 [L]

    It should work.
     
    vishwaa, Jun 23, 2006 IP
    The Webmaster likes this.
  16. The Webmaster

    The Webmaster IdeasOfOne

    Messages:
    9,516
    Likes Received:
    718
    Best Answers:
    0
    Trophy Points:
    360
    #336
    Thanks but this is not what I want.
    What it does that it redirect from /dir/play/123.htm to index.php?act=play&id=123
    (But Images and css linking are not working)

    My site is dynamic, what I want that it should reflect the dynamic URL as static URLs.

    The rule you have given above, I'd have to update all the links on my site, isnt it??
     
    The Webmaster, Jun 23, 2006 IP
  17. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #337
    vishwaa, Jun 23, 2006 IP
    amitpatel_3001 likes this.
  18. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #338
    He's correct. domain.com/.htaccess for da first example.

    [R=301,L] is what you put for redirect. [L] is for changing da URLs.

    Just keep da first two lines out, since they messed you up last time.
     
    Nintendo, Jun 23, 2006 IP
  19. The Webmaster

    The Webmaster IdeasOfOne

    Messages:
    9,516
    Likes Received:
    718
    Best Answers:
    0
    Trophy Points:
    360
    #339
    Ohh well
    umm!!! I think what I want is something different.
    right now my URL looks like - index.php?act=play&id=123
    I want when a person follows these URLs, the URL he gets should be play/123.html

    the rule mentioned by Vishwa doesnt do this, all it does is it makes a fake URL play/123.htm but the URL doesnt change automatically.

    If I put 301 there it redirects from /play/123.htm to index.php?act=play&id=123 but I want other way round.

    Is it possible???
     
    The Webmaster, Jun 24, 2006 IP
  20. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #340
    .htaccess doesn't change da links, it just makes da URLs work!! :D You have to edit da script to change da links. :D
     
    Nintendo, Jun 24, 2006 IP