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.

FAQ: mod_rewrite, 301 redirects, and optimizing Apache.

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

  1. danzor

    danzor Peon

    Messages:
    208
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #281
    Hm.. Is it possible that someone here can whip me up something that does this?
    I'd like all .mp3,wav,mpg etc files to be 'redirected' somewhere else.. a blank file preferably. This is to prevent bandwidth leeching. I don't care whether the links don't load properly in the user's media player.
     
    danzor, Apr 27, 2006 IP
  2. browntwn

    browntwn Illustrious Member

    Messages:
    8,347
    Likes Received:
    848
    Best Answers:
    7
    Trophy Points:
    435
    #282
    browntwn, May 4, 2006 IP
  3. tonyinabox

    tonyinabox Peon

    Messages:
    1,988
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    0
    #283
    Thank you very much. This thread help me to understand mod_rewrite easier and I just apply to my web directory

    http://directory.krpmag.com/

    hehe
     
    tonyinabox, May 21, 2006 IP
  4. Julia-IT-Inventors

    Julia-IT-Inventors Active Member

    Messages:
    369
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    58
    #284
    Hi guys, maybe you can help me, it's the third day I am fighting with rewrite and it still wins :(

    I have a php ld directory and I am trying to make it seo friendly before annoucement.
    Now I am using rewrite like this:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^juliawebdirectory\.com
    RewriteRule ^(.*)$ http://www.juliawebdirectory.com/$1 [R=permanent,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^Architecture(.*) index.php [R=301,L]

    it worked fine for several lines but there are 273 lines for categories and subcategories and after ~30th pages start returning 404 error. Now there are [R=301,L] for all lines and none of them work.

    If I delete [R=301,L] everything works fine but I would like to have exactly 301 redirect instead of 302 defalt.

    What am I doing wrong, how to fix the problem? And can somebody help me with code for making urls of category and subcategory pages to be like this

    http://www.juliawebdirectory.com/Arts/Architecture.php
    http://www.juliawebdirectory.com/Arts/Architecture2.php

    and so on

    instead of current http://www.juliawebdirectory.com/Arts/Architecture/

    Thank you!
    Julia
     
    Julia-IT-Inventors, May 27, 2006 IP
  5. sebastya

    sebastya Well-Known Member

    Messages:
    2,449
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    138
    #285
    This code doesn't work for me, can someone help?

    percentageproducts.com/home.php?id=main

    to

    percentageproducts.com/main.htm

    Please help.

    Thanks
     
    sebastya, May 27, 2006 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #286
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^([^.]+)\.htm$ home.php?id=$1 [L]

    or for only that one URL,

    RewriteRule ^main\.htm$ home.php?id=main [L]


    JII, make a thread about that one.
     
    Nintendo, May 27, 2006 IP
  7. sebastya

    sebastya Well-Known Member

    Messages:
    2,449
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    138
    #287
    Thanks man.
     
    sebastya, May 28, 2006 IP
  8. 2003m2003

    2003m2003 Well-Known Member

    Messages:
    863
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    138
    #288
    2003m2003, May 31, 2006 IP
  9. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #289
    er why even use mod_rewrite if it won't be static. Changing the URL is worthless.

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^test.php?user_id=([^.]+)$ classifieds/test.php?user_id=$1 [L]
     
    Nintendo, May 31, 2006 IP
  10. 2003m2003

    2003m2003 Well-Known Member

    Messages:
    863
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    138
    #290
    Thanks Nintendo, But it doesn't work, seems something wrong some where.

    Why I need this....Already I have static urls by modrewrite, in these pages, there are links to page like this
    http://test.com/test.php?user_id=1 but these pages don't load since correct url is http://test.com/classifieds/test.php?user_id=1 in the folder 'classified'
    I can't change links in those pages by changeing HTML, since it will affect pages without modrewiting. I want to keep both modrewrited pages as well as pages without modrewrite.

    Hope you understand my problrm.
     
    2003m2003, May 31, 2006 IP
  11. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #291
    Do this little test and see if mod_rewrite even works.

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^wacko\.html$ index.php [L]

    Change index.php if that's not the URL of the index page, then go to

    domain.com/wacko.html

    If you got mod_rewrite, that URL will work.
     
    Nintendo, May 31, 2006 IP
  12. tonyinabox

    tonyinabox Peon

    Messages:
    1,988
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    0
    #292
    I have some question,, my mod_rewrite didn't work in the way I want. I'm not sure what's wrong

    I want to use it for image anti-leeching by redirect to my script with image URL and produce the image

    Please tell me what's wrong with above code.
     
    tonyinabox, May 31, 2006 IP
  13. 2003m2003

    2003m2003 Well-Known Member

    Messages:
    863
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    138
    #293
    Mod_rewite working fine. I will PM and show page where it is not working.
     
    2003m2003, May 31, 2006 IP
  14. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #294
    Make a thread for that. If it's not URL changing, I'm a n00bie at it.
     
    Nintendo, May 31, 2006 IP
  15. tonyinabox

    tonyinabox Peon

    Messages:
    1,988
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    0
    #295
    I see. thank you, but yeah.. i use URL changing for my directory and work pretty well.
     
    tonyinabox, May 31, 2006 IP
  16. The Webmaster

    The Webmaster IdeasOfOne

    Messages:
    9,516
    Likes Received:
    718
    Best Answers:
    0
    Trophy Points:
    360
    #296
    I am stuck and I need a help,

    I have a site made in ASP hosted on Windows server, now I have to move the site on linux/Apache server which does not support ASP, I got the site translated in the PHP/HTML. but the problem is that all the ASP pages are listed in the search engines and have good PR.
    Is there any way that I can rewrite my URLs as such that they ommit .asp extention, new page names are the same as old one.
    i.e - webpackage.asp is now changed to webpackage.htm and I want that when retirved it should ommit the page as the old name with .asp extention.

    ASP sucks, help me please. :)
     
    The Webmaster, Jun 1, 2006 IP
  17. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #297
    Oh gees...:D You're only posting in here because...!!! :D

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.*)\.asp$ http://www.domain.com/$1.html [R=301,L]

    redirects from asp to html to destroy the duplicate content bug...once Google updates it...one of these years.

    That'll be $49.99 for the super secret code. :D
     
    Nintendo, Jun 1, 2006 IP
  18. The Webmaster

    The Webmaster IdeasOfOne

    Messages:
    9,516
    Likes Received:
    718
    Best Answers:
    0
    Trophy Points:
    360
    #298
    Not Working
    Server error!
    
    The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script. 
    
    If you think this is a server error, please contact the webmaster. 
    Error 500
    HTML:
    Giving me this error, when I placed it under WWW folder or My site folder.
     
    The Webmaster, Jun 1, 2006 IP
  19. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #299
    Try this test

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^wacko\.html$ index.html [L]

    domain.com/.htaccess

    Change index.html to what ever the index file name is. Then domain.com/wacko.html should show the index page.
     
    Nintendo, Jun 1, 2006 IP
  20. The Webmaster

    The Webmaster IdeasOfOne

    Messages:
    9,516
    Likes Received:
    718
    Best Answers:
    0
    Trophy Points:
    360
    #300
    Nope its too not working, giving the same error.
     
    The Webmaster, Jun 1, 2006 IP