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
    #81
    RewriteRule ^search/([^.]+)/([^.]+)\.html$ search.html?author=&category=&keyword=&number=&x=$1&y=$2 [L,NS,NC,QSA]

    if only X and y ever have anything

    domain.com/search/XXXXX/YYYYY.html

    RewriteRule ^search/([^.]+)/([^.]+)/([^.]+)/([^.]+)/([^.]+)/([^.]+)\.html$ search.html?author=$1&category=$2&keyword=$3&number=$4&x=$5&y=$6 [L,NS,NC,QSA]

    if all of them do.

    domain.com/search/AUTHOR/CATEGORY/KEYWORD/NUMBER/XXX/YYY.html
     
    Nintendo, Oct 10, 2005 IP
  2. Imran

    Imran Notable Member

    Messages:
    2,340
    Likes Received:
    190
    Best Answers:
    0
    Trophy Points:
    230
    #82
    what about the images and other tings with this path? I have o make changes in the script?
    Thanks!
     
    Imran, Oct 10, 2005 IP
  3. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #83
    You got to change the script so the links go to the new URLs!
     
    Nintendo, Oct 10, 2005 IP
    Imran likes this.
  4. Imran

    Imran Notable Member

    Messages:
    2,340
    Likes Received:
    190
    Best Answers:
    0
    Trophy Points:
    230
    #84
    yeh, thats the main part! Changing the Script!
    Thanks!
     
    Imran, Oct 11, 2005 IP
  5. webdesignlab

    webdesignlab Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #85
    I am having a lot of trouble with this Rewrite.

    I have http://www.ilovehuatulco.com/huatulco/viewforum.php?f=1 that I am trying with the able2know script to cahnge to http://www.ilovehuatulco.com/huatulco/forum-1.html

    Ok I do have mod_rewrite on my server aftger a little test.

    My .htaccess is
    ...............................................
    RewriteEngine On
    RewriteRule ^post-([0-9]*).html&highlight=([a-zA-Z0-9]*) viewtopic.php?p=$1&highlight=$2 [L,NC]
    RewriteRule ^post-([0-9]*).* viewtopic.php?p=$1 [L,NC]
    RewriteRule ^view-poll([0-9]*)-([0-9]*)-([a-zA-Z]*).* viewtopic.php?t=$1&postdays=$2&postorder=$3&vote=viewresult [L,NC]
    RewriteRule ^about([0-9]*).html&highlight=([a-zA-Z0-9]*) viewtopic.php?t=$1&highlight=$2 [L,NC]
    RewriteRule ^about([0-9]*).html&view=newest viewtopic.php?t=$1&view=newest [L,NC]
    RewriteRule ^about([0-9]*)-([0-9]*)-([a-zA-Z]*)-([0-9]*).* viewtopic.php?t=$1&postdays=$2&postorder=$3&start=$4 [L,NC]
    RewriteRule ^about([0-9]*)-([0-9]*).* viewtopic.php?t=$1&start=$2 [L,NC]
    RewriteRule ^about([0-9]*).* viewtopic.php?t=$1 [L,NC]
    RewriteRule ^about([0-9]*).html viewtopic.php?t=$1&start=$2&postdays=$3&postorder=$4&highlight=$5 [L,NC]
    RewriteRule ^mark-forum([0-9]*).html* viewforum.php?f=$1&mark=topics [L,NC]
    RewriteRule ^updates-topic([0-9]*).html* viewtopic.php?t=$1&watch=topic [L,NC]
    RewriteRule ^stop-updates-topic([0-9]*).html* viewtopic.php?t=$1&unwatch=topic [L,NC]
    RewriteRule ^forum-([0-9]*).html viewforum.php?f=$1 [L,NC]
    RewriteRule ^forum-([0-9]*).* viewforum.php?f=$1 [L,NC]
    RewriteRule ^topic-([0-9]*)-([0-9]*)-([0-9]*).* viewforum.php?f=$1&topicdays=$2&start=$3 [L,NC]
    RewriteRule ^ptopic([0-9]*).* viewtopic.php?t=$1&view=previous [L,NC]
    RewriteRule ^ntopic([0-9]*).* viewtopic.php?t=$1&view=next [L,NC]

    ...........................................

    I guess there are a million reasons this is not working, but any light would be great.

    Cheers

    Kevin
     
    webdesignlab, Oct 14, 2005 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #86
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^post\-([^.]+)\.html&highlight=([^.]+)$ viewtopic.php?p=$1&highlight=$2 [L,NC]
    RewriteRule ^post\-([^.]+)$ viewtopic.php?p=$1 [L,NC]
    RewriteRule ^view\-poll([^.]+)\-([^.]+)$ viewtopic.php?t=$1&postdays=$2&postorder=$3&vote=viewresult [L,NC]
    RewriteRule ^about([^.]+).html&highlight=([^.]+)$ viewtopic.php?t=$1&highlight=$2 [L,NC]
    RewriteRule ^about([^.]+).html&view=newest$ viewtopic.php?t=$1&view=newest [L,NC]
    RewriteRule ^about([^.]+)\-([^.]+)\-([^.]+)\-([^.]+)$ viewtopic.php?t=$1&postdays=$2&postorder=$3&start=$4 [L,NC]
    RewriteRule ^about([^.]+)\-([^.]+)$ viewtopic.php?t=$1&start=$2 [L,NC]
    RewriteRule ^about([^.]+)$ viewtopic.php?t=$1 [L,NC]
    RewriteRule ^about([^.]+)\.html$ viewtopic.php?t=$1&start=$2&postdays=$3&postorder=$4&highlight=$5 [L,NC]
    RewriteRule ^mark\-forum([^.]+)\.html* viewforum.php?f=$1&mark=topics [L,NC]
    RewriteRule ^updates\-topic([^.]+)\.html*$ viewtopic.php?t=$1&watch=topic [L,NC]
    RewriteRule ^stop\-updates\-topic([^.]+)\.html*$ viewtopic.php?t=$1&unwatch=topic [L,NC]
    RewriteRule ^forum\-([^.]+)\.html$ viewforum.php?f=$1 [L,NC]
    RewriteRule ^forum\-([^.]+)$ viewforum.php?f=$1 [L,NC]
    RewriteRule ^topic\-([^.]+)\-([^.]+)\-([^.]+)$ viewforum.php?f=$1&topicdays=$2&start=$3 [L,NC]
    RewriteRule ^ptopic([^.]+)$ viewtopic.php?t=$1&view=previous [L,NC]
    RewriteRule ^ntopic([^.]+)$ viewtopic.php?t=$1&view=next [L,NC]

    This is closer, but not correct 100%, becase for example

    RewriteRule ^post\-([^.]+)\.html&highlight=([^.]+)

    looks like you want the URL as

    domain.com/post-WHATEVER.html&highlight=WHATEVER
     
    Nintendo, Oct 14, 2005 IP
  7. webdesignlab

    webdesignlab Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #87
    Hi,

    Thanks for the reply. I have to admit that I am out of my league here, but I want this to work so I will jump through any hoops I need.

    I did as you reccomended and now I get an internal server error "file not found' please see http://www.ilovehuatulco.com/huatulco/forum-1.html.

    The main script that it is trying to sepak to is 'includes/page_header.php' to which I added ...

    .................................................................
    if ( !$userdata['session_logged_in'] )
    {
    ob_start();
    function replace_for_mod_rewrite(&$s)
    {
    $urlin =
    array(
    "'(?<!/)viewforum.php\?f=([0-9]*)&amp;topicdays=([0-9]*)&amp;start=([0-9]*)'",
    "'(?<!/)viewforum.php\?f=([0-9]*)&amp;mark=topics'",
    "'(?<!/)viewtopic.php\?t=([0-9]*)&amp;watch=topic*'",
    "'(?<!/)viewtopic.php\?t=([0-9]*)&amp;unwatch=topic*'",
    "'(?<!/)viewtopic.php\?t=([0-9]*)&amp;highlight=*'",
    "'(?<!/)viewforum.php\?f=([0-9]*)'",
    "'(?<!/)viewtopic.php\?t=([0-9]*)&amp;view=previous'",
    "'(?<!/)viewtopic.php\?t=([0-9]*)&amp;view=next'",
    "'(?<!/)viewtopic.php\?t=([0-9]*)&amp;postdays=([0-9]*)&amp;postorder=([a-zA-Z]*)&amp;vote=viewresult'",
    "'(?<!/)viewtopic.php\?t=([0-9]*)&amp;postdays=([0-9]*)&amp;postorder=([a-zA-Z]*)&amp;start=([0-9]*)'",
    "'(?<!/)viewtopic.php\?t=([0-9]*)&amp;start=([0-9]*)&amp;postdays=([0-9]*)&amp;postorder=([a-zA-Z]*)&amp;highlight=([a-zA-Z0-9]*)'",
    "'(?<!/)viewtopic.php\?t=([0-9]*)&amp;start=([0-9]*)'",
    "'(?<!/)viewtopic.php\?t=([0-9]*)'",
    "'(?<!/)viewtopic.php&amp;p=([0-9]*)'",
    "'(?<!/)viewtopic.php\?p=([0-9]*)'",
    );
    $urlout = array(
    "topic-\\1-\\2-\\3.html",
    "mark-forum\\1.html",
    "updates-topic\\1.html",
    "stop-updates-topic\\1.html",
    "about\\1.html&amp;highlight=\\2",
    "forum-\\1.html",
    "ptopic\\1.html",
    "ntopic\\1.html",
    "view-poll\\1-\\2-\\3.html",
    "about\\1-\\2-\\3-\\4.html",
    "about\\1.html",
    "about\\1-\\2.html",
    "about\\1.html",
    "post-\\1.html",
    "post-\\1.html",
    );
    $s = preg_replace($urlin, $urlout, $s);
    return $s;
    }
    }
    .................................................................

    Just to give you a little background.

    Cheers

    Kevin
     
    webdesignlab, Oct 16, 2005 IP
  8. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #88
    I stink at php. You might want to try hireing some one to get it all working.

    RewriteBase /

    to

    RewriteBase /huatulco/

    And with the .htaccess file at domain.com/.htaccess
     
    Nintendo, Oct 17, 2005 IP
  9. webdesignlab

    webdesignlab Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #89
    Oh my god it worked with just moving it to /huatulco/ woweee.

    I am so thankful to you for spending the time to help out.

    Cheers

    If you ever need a hotel in Huatulco just tell me.

    Kevin
     
    webdesignlab, Oct 17, 2005 IP
  10. Nathan Malone

    Nathan Malone Well-Known Member

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #90
    How would I go about rewriting site.com/directory/category.php?cat_id=123 to site.com/directory/category-123/ ? I have tried doing this, but when I use the following code, it takes an extra ten seconds or so for the server to send the page. If I rewrite it to .../category-123.html , it sends it instantly.

    The code I was trying is below:

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /directory/
    RewriteRule ^category\-([0-9]*)/$ category.php?cat_id=$1 [L]
    Code (markup):
    And the .htaccess file is in the /directory/ directory. Any suggestions? My site is hosted at HostGator if that matters. Thanks,
     
    Nathan Malone, Oct 18, 2005 IP
  11. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #91
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /directory/
    RewriteRule ^category\-([^.]+)/$ category.php?cat_id=$1 [L]

    Or try it at domain.com/.htaccess

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /
    RewriteRule ^directory/category\-([^.]+)/$ directory/category.php?cat_id=$1 [L]
     
    Nintendo, Oct 18, 2005 IP
  12. classifieds

    classifieds Sopchoppy Flash

    Messages:
    825
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    150
    #92
    Nintendo,

    I just discovered that the dynamic calendar on one of my sites had been indexed out to the year 3050 (empty pages for all months, days, weeks, event detail) in all total about 80k pages. The Google jagger update does not like this AT ALL.

    I've removed the calendar but the pages are still in Google's index.

    The site is mambo and the calendar is call "Events Calendar"

    How would I build a modrewrite to issue a 404 anytime one of the calendar pages are referenced?

    The calendar URLs have the format of:

    www.wakulla.com/option,com_events/task,view_cat/catid,175/year,2005/month,09/day,29/Itemid,1/


    The calendar component name called "com_events."

    Any advice on how I could filter on and issue a 404 for these URLs?:

    "www.wakulla.com/option,com_events" or
    "www.wakulla.com/index.php?option=com_events"



    Thanks if you can help.

    -jay
     
    classifieds, Oct 19, 2005 IP
  13. Nathan Malone

    Nathan Malone Well-Known Member

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #93
    Thanks for the help, however, when I use the above code, the page takes at least 10-20 extra seconds to load. Any suggestions? The server currently works fine for url's written as .../directory/category-123.html

    Thank you,
     
    Nathan Malone, Oct 19, 2005 IP
  14. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #94
    What did the .htaccess file look like when it was fast going to .../category-123.html

    Was .html instead of / the only change?

    :::Any advice on how I could filter on and issue a 404 for these URLs?:

    You might want to make a new thread for that. I'm not sure if robots.txt could do anything like that.
     
    Nintendo, Oct 19, 2005 IP
  15. classifieds

    classifieds Sopchoppy Flash

    Messages:
    825
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    150
    #95
    Do you think it can be done with a modrewrite?
    -jay
     
    classifieds, Oct 19, 2005 IP
  16. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #96
    I'm not sure how to redirect only Google to a dead URL.
     
    Nintendo, Oct 19, 2005 IP
  17. classifieds

    classifieds Sopchoppy Flash

    Messages:
    825
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    150
    #97
    sorry. . .

    All URL requests would be 404'd .

    I've deleted the calendar pages. . and the mambo component manager has a bad habit of doing a 200 status code and then a 302 redirect to a page that says "this page does not exist" .

    So I want apache to give everyone a 404 .

    -jay
     
    classifieds, Oct 19, 2005 IP
  18. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #98
    ErrorDocument 404 /file.html

    is a guess.
     
    Nintendo, Oct 19, 2005 IP
  19. classifieds

    classifieds Sopchoppy Flash

    Messages:
    825
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    150
    #99
    Thank you for your patience. I'm not asking the right question or not asking the right question correctly :eek:


    Would this rewrite rule:

    RewriteRule ^option\,com_events [F] 
    Code (markup):

    Generate a 404 error for the following URL:

    http://www.wakulla.com/option,com_events/task,view_cat/catid,175/year,2005/month,09/day,29/Itemid,1/
    Code (markup):
     
    classifieds, Oct 19, 2005 IP
  20. Nathan Malone

    Nathan Malone Well-Known Member

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #100
    The current line in the .htaccess file is this:

    RewriteRule ^category\-([0-9]*)\.html$ category.php?t=$1 [L,NC]
    Code (markup):
    I know that the following also works:

    RewriteRule ^category-([0-9]*).html category.php?t=$1 [L,NC]
    Code (markup):
     
    Nathan Malone, Oct 19, 2005 IP