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. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #101
    RewriteRule ^category-([0-9]*)/$ category.php?t=$1 [L,NC]

    if your just trying to change it from .html to a directory


    Only way I know how to generate a 404 is to delete the files, and if you want to, redirect all the 404 pages to a certian URL, using a code like
    ErrorDocument 404 /file.html
     
    Nintendo, Oct 19, 2005 IP
  2. DavidAusman

    DavidAusman Peon

    Messages:
    399
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #102
    Nintendo, after applying the mod_rewrite, everything was fine unless that it shows error code of 500 to some engine. for example:
    http://whois.sc/hotwebtools.com

    **does this effect googlebot from crawling?
    Thanks
     
    DavidAusman, Oct 20, 2005 IP
  3. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #103
    Post your .htaccess code.
     
    Nintendo, Oct 20, 2005 IP
  4. DavidAusman

    DavidAusman Peon

    Messages:
    399
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #104
    i have several folder, every folder got its own .htaccess. This is one of them
    ------------------------
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^viewArticles/(.*)/(.*)/(.*)\.html$ articles/viewArticles.php?aID=$1&subCatID=$2&catID=$3 [L]
    RewriteRule ^subCat/(.*)/(.*)\.html$ articles/subCat.php?subCatID=$1&catID=$2 [L]
    RewriteRule ^subCatMore/(.*)/(.*)\.html$ articles/subCat.php?set=$1&subCatID=$2 [L]
    RewriteRule ^category/(.*)\.html$ articles/cat.php?catID=$1 [L]
     
    DavidAusman, Oct 20, 2005 IP
    keral82 likes this.
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #105
    It's correct. I once had almost a million URLs indexed in Google thanks to mod_rewrite.
     
    Nintendo, Oct 20, 2005 IP
  6. keral82

    keral82 Banned

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

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #107
    How do you want the static URLs to look like?

    Gah!!!! Nitendo...how many more names will they come up with!!!! :D You would think that with Nintendo being so populer, every one would give me one name, yet I'm da only one here with more than one name. Geting closer to 10 names now!!!! *Thinks I should of just registered as 'Wacko'!!!!! :D
     
    Nintendo, Oct 21, 2005 IP
  8. keral82

    keral82 Banned

    Messages:
    781
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #108
    Anything you say. I don't care what they look like as long as they look static to SE's and sorry for that name thing. "NINTENDO" this time I am sorry for that. Also thanks for replying so fast.
     
    keral82, Oct 21, 2005 IP
  9. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #109
    Nintendo, Oct 21, 2005 IP
  10. keral82

    keral82 Banned

    Messages:
    781
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #110
    Are you god of mod_rewrite.

    Thanks. Thank You very much. I think you have invented this mod_rewrite thing.
     
    keral82, Oct 21, 2005 IP
  11. keral82

    keral82 Banned

    Messages:
    781
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #111
    And also let me know that would I have to edit the whole script for this thing to work. Means all the links in my pages. that currently point to the dynamic URL.
     
    keral82, Oct 21, 2005 IP
  12. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #112
    What ever script you use has to be changed to link to the new URLs! mod_rewrite only makes the cool URLs work!

    domain.com/.htaccess is where that code goes.
     
    Nintendo, Oct 21, 2005 IP
  13. keral82

    keral82 Banned

    Messages:
    781
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #113
    Okay will think about it.. Too much work to be done I think so. Can't I write something that would point directly to the new url's in my cinfig.php which is included on every page?
     
    keral82, Oct 21, 2005 IP
  14. keral82

    keral82 Banned

    Messages:
    781
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #114
    one thing more that I forgot to ask what will come in .htaccess

    For this: http://localhost/articles/ShowCategory.php?

    CategoryID=17&SubcategoryID=44

    Thanks.

    I wrote this is it correct?

    RewriteRule ^subcategory/([^.]+)\.html$ ShowCategory.php?CategoryID=$1&SubcategoryID=$2 [L]
     
    keral82, Oct 21, 2005 IP
  15. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #115
    RewriteRule ^category/([^.]+)/subcategory/([^.]+)\.html$ articles/ShowCategory.php?CategoryID=$1&SubcategoryID=$2 [L]
     
    Nintendo, Oct 22, 2005 IP
  16. Ethiccash

    Ethiccash Peon

    Messages:
    150
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #116
    Can someone explain this to me. I'm trying to do that, with no success :

    I have www.mydomain.com/articles/show.php?id=xxxx (xxx are numbers)
    I have a script that makes a sitemap : I've changed the script to link to www.mydomain.com/article_category/article_name in the sitemap an no more to sho.php?id=xxx

    Now I don't know how to make the last step : opening the id=xxx article which corresponds to article_category/article_name.

    I've tried the above in the FAQ, but I'm a "bit" lost

    Thanks for your help

    I'd like to have www.mydomain.com
     
    Ethiccash, Nov 7, 2005 IP
  17. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #117
    You have to know how to edit the script to spit out the URL with the article name in it, or manually add it in every single link, if the links are on static pages.
     
    Nintendo, Nov 7, 2005 IP
  18. Ethiccash

    Ethiccash Peon

    Messages:
    150
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #118
    Thanks,
    I'm not sure I understand very well :

    Initially my sitemap file had links "show.php?id=xxxx"

    I've changed the script so that links in the sitemap are now "article_category/article_name.htm" (article_category and article_name are the infos related to id=xxx in the database)

    My problem is that when I mod rewrite, I have to make something so that the server knows that id=xxx coressponds to the database record with article_category and article_name

    Sorry, but it's really not my core competencies...
     
    Ethiccash, Nov 8, 2005 IP
  19. Nintendo

    Nintendo ♬ King of da Wackos ♬

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

    If the URL is domain.com/id/name.htm with script URL as show.php?id=xxxx
     
    Nintendo, Nov 8, 2005 IP
  20. unprofundity

    unprofundity Peon

    Messages:
    45
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #120
    thank for the tips nintendo.

    i am simply learning how to mod_rewrite using the help on the thread.
    unfortunately, i am getting errors.

    i am trying to mod-rewrite the search results page of the digitalpoint google api search software.

    i have this mod setup on my .htaccess on my root domain.
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /search
    RewriteRule ^search/(.*)\.html$ search/search.php?q=$1

    but i can only attain this.

    http://example.com/search/search.php/searchkeyword

    and i looks quite ok.

    but what i really want is to rewrite like this.

    http://example.com/searchfolder/searchkeyword/

    can anyone help me out on this? thank you in advance!
     
    unprofundity, Nov 8, 2005 IP