FAQ: mod_rewrite, 301 redirects, and optimizing Apache.

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

  1. potter

    potter Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #401
    I have been in contact with our websupplier and they are reffering to this doc: http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html but I ca't figure out what to do, plse help.
     
    potter, Sep 8, 2006 IP
  2. potter

    potter Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #402
    I have now tried according attached doc. But nothing shows in my url (its the same as before)
     

    Attached Files:

    potter, Sep 8, 2006 IP
  3. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #403
    You have to change the links to the new URLs.
     
    Nintendo, Sep 8, 2006 IP
  4. potter

    potter Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #404
    Ok, now I get it. But this effects also other stuff in my site, like images other links etc. I have also built in security around what can be transfered in show, go, page_id and lang. For an example you should not be able to put in a value in show higher then 8, in go we only except predefined pages and so on.
    Like this:
    //This is the allowed pages connected to $go
    $allowed_pages = array('sidor/allmvillk.php', 'sidor/andra_order.php');
    if (in_array($_GET['go'], $allowed_pages)){
    include($_GET['go']);
    }

    I don't know if its possible to only effects my menu links?

    Otherwise this means I need to rebuild my hole site.
     
    potter, Sep 8, 2006 IP
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #405
    You have to change the image and link codes as if the fake URLs are the real URLs. Browsers don't know the URLs are fake and don't know what the real URLs are.
     
    Nintendo, Sep 8, 2006 IP
  6. leeds1

    leeds1 Peon

    Messages:
    585
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #406
    I have searched high and low and thought I now need to come back to Nintendo for a fast response.

    It should be simple :)

    How do I 301 redirect a directory to the same subdomain

    So that www .domain.com/directory/ becomes directory.domain.com

    and www .domain.com/directory/directory2/file1.html then becomes directory.domain.com/directory2/file1.html

    ?

    thanks
     
    leeds1, Sep 12, 2006 IP
  7. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #407
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^directory/(.*)$ http://directory.domain.com/$1 [R=301,L]
    RewriteRule ^directory/$ http://directory.domain.com/ [R=301,L]

    The first RewriteRule *might* help redirect URLs in the directory, like categories, though I'm not sure.
     
    Nintendo, Sep 12, 2006 IP
  8. JohnHanson

    JohnHanson Guest

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #408
    Hi, I am using PHPLD directory script and am having some troubles with mod-rewrite. Should i be enter my rewrite in mysite.com/.htaccess or in mysite.com/directory/.htaccess .

    The mod re-write i am trying to make work is:

    mysite.com/directory/details.php?id=16

    to go to

    mysite.com/directory/company-16.php

    Hope you can help, as i want to know for sure if the problem is with my mod re-write or some problem with the directory script and conflicts with the built in mod re-write. Thanks :)
     
    JohnHanson, Sep 13, 2006 IP
  9. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #409
    domain.com/.htaccess

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^directory/company-([^.]+)\.php$ directory/details.php?id=$1 [L]

    Using .html instead of .php would be much better in the eyes of some search engines.
     
    Nintendo, Sep 13, 2006 IP
  10. XantosNew

    XantosNew Peon

    Messages:
    599
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #410
    Hi there I need some advise:

    I have pages that are generated by:
    RewriteRule ([^-]*)-page-([0-9]*).html index.php?action=nameview&nameID=$2 [L]

    this generates pages like:
    name-page-1.html

    ===============================================

    I want to redirect 301:

    /name-page-1.html?PHPSESSID=xxxxxxxxxxxxxxxxxxxxx

    to go to

    http://www.mydomain.com/name-page-1.html

    What is the best way to do that?
     
    XantosNew, Sep 16, 2006 IP
  11. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #411
    Edit the script so that doesn't show up in the link.

    Search for

    PHPSESSID

    one of them will be for the link.
     
    Nintendo, Sep 16, 2006 IP
  12. XantosNew

    XantosNew Peon

    Messages:
    599
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #412
    I have edited the scripts so it will add no more
    ?PHPSESS... in the url-s

    However all of my links are
    indexed by g**le:
    duplicated or even threepled
    with different ?PHPSESS... in the url-s

    so I want ro redirect all the links with ?PHPSESS... in the url-s
    to the links without ?PHPSESS... in the url-s
     
    XantosNew, Sep 17, 2006 IP
  13. ottodo

    ottodo Guest

    Messages:
    2,055
    Likes Received:
    70
    Best Answers:
    0
    Trophy Points:
    0
    #413
    @Nintendo you doing great work :)
    but there is question in my mind i hope u answer me:
    why this for isn't optimized? (and most of da forums VB-IPB-phpBB)?
     
    ottodo, Sep 17, 2006 IP
  14. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #414
    Session Ids...toast until google updates da listings!!!!

    http://www.google.com/search?q=site:forums.digitalpoint.com

    You don't fix something that's not broken!!!!

    And not all servers can do mod_rewrite. aka...servers that live in a window.
     
    Nintendo, Sep 18, 2006 IP
  15. XantosNew

    XantosNew Peon

    Messages:
    599
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #415
    Hi Nintendo ,
    whats wrong with that for removig ?phpsess......
    from the link: something-page-10.html?phpsess......

    RewriteRule something-page-10.html(.*)$ something-page-10.html [R=301,L]
     
    XantosNew, Sep 18, 2006 IP
  16. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #416
    You can try it, but I don't think it'll work since it has ? and = in the part you want redirected.
     
    Nintendo, Sep 18, 2006 IP
  17. XantosNew

    XantosNew Peon

    Messages:
    599
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #417
    this is not working:
    RewriteRule something-page-10.html(.*)$ something-page-10.html [R=301,L]

    this is not working either:
    RewriteRule something-page-10.html?PHPSESSID=(.*)$ something-page-10.html [R=301,L]

    any help will be appreciated
     
    XantosNew, Sep 18, 2006 IP
  18. eXe

    eXe Notable Member

    Messages:
    4,643
    Likes Received:
    248
    Best Answers:
    0
    Trophy Points:
    285
    #418
    Nintendo, maybe you can help me out here?
     
    eXe, Sep 18, 2006 IP
  19. XantosNew

    XantosNew Peon

    Messages:
    599
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #419
    So is there anythik that I can do to sort the problem with
    " ? and = " in the part of redirecting script to make it working?

    this is not working either:
    RewriteRule something-page-10.html?PHPSESSID=(.*)$ something-page-10.html [R=301,L]

    I have reade lots of posts in the internet and did not find the clue for solving this.

    I'm looking for working solution
     
    XantosNew, Sep 19, 2006 IP
  20. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #420
    Post at

    webmasterworld.com/apache/

    Yes, it's possible, if you have some

    RewriteCond %{QUERY_STRING}

    giberish stuff. For example, I once redirected a php vBulletin thread to a new thread after the original massive thread was deleted.

    RewriteCond %{QUERY_STRING} ^t=10285(&page=[^&]+)?$
    RewriteRule ^showthread\.php$ http://www.domain.com/showthread.php?t=$1 [R=301,L]
     
    Nintendo, Sep 19, 2006 IP