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

    expat Stranger from a far land

    Messages:
    873
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #41
    RewriteEngine on
    Options +FollowSymLinks
    RewriteCond %{HTTP_HOST} ^mydomain\.com
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=permanent,L]
    SEMrush
    works for me
    Expat
     
    expat, Aug 24, 2005 IP
    SEMrush
  2. davert

    davert Banned

    Messages:
    345
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #42
    davert, Aug 24, 2005 IP
  3. expat

    expat Stranger from a far land

    Messages:
    873
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #43
    mmmhh...
    try dropping the last /
    RewriteRule ^(.*)$ http://www.mydomain.com$1 [R=permanent,L]

    Although when you say log in .... is your login redirecting?
    The script should not add an extra /......
    As the above may give problems on simple input mydonain.com

    expat
     
    expat, Aug 24, 2005 IP
  4. davert

    davert Banned

    Messages:
    345
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #44
    OK - will try. Sorry, I didn't mean anything by log in...

    WORKS!! Thanks!! No problem on either domain.com or domain.com/something.html

    Now to see if we can FINALLY budge Google over a PR of 6!
     
    davert, Aug 29, 2005 IP
  5. theblade24

    theblade24 Active Member

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #45
    Currently I use this mod_rewrite method and have for a year or so. I am very well spidered and ranked.

    Not knowing how back when I did it, my urls end in /MM-fitieiwk (my product reference code) with no page extension.

    I see now how to do it so that they can all end in .html. But my question is....what will happen to all the pages spidered without .html......when they are re-spidered will the old ones drop off? Will my rankings rise or decline because of adding the .html ?

    I have 8000 products and this will change all of the urls obviously. Is it worth doing? How would I do it effectively? Can the old ones be 301 redirected to the new ones with .html using an all inclusive redirect so during the changeover they'll point to the new ones?

    Advice? Don't want to make another mistake....

    Thanks!
     
    theblade24, Sep 7, 2005 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #46
    Changing any static URL to another static URL would be a mistake, unless the search engines havn't found the file! If it's not broke, don't try to fix it!!! If you do it, include the 301 redirect and hope the search engines still like your listings! Just adding a .html will never help a listing. Only if for example, the new URL added the product names to the URL would I do it.
     
    Nintendo, Sep 7, 2005 IP
  7. Henny

    Henny Peon

    Messages:
    2,118
    Likes Received:
    241
    Best Answers:
    0
    Trophy Points:
    0
    #47
    OK, I am lost, for one of my sites my url is this:

    .com/index.php?mode=Apparel&item=B0009VX8XQ
    I wrot the line in htaccess:
    RewriteRule ^index/(.*)/(.*)\.shtml$ index.php?mode=$1&item=$2 [L]

    No joy, any clues? I tried it with and without the front hacks.
     
    Henny, Sep 15, 2005 IP
  8. theblade24

    theblade24 Active Member

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #48
    Ok, lets say I add the product name to the url.

    Is there a way to 301 redirect ANY call to any older style rewritten url to the new one?

    I guess it might be redirecting an already mod rewritten url to another?

     
    theblade24, Sep 15, 2005 IP
  9. expat

    expat Stranger from a far land

    Messages:
    873
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #49
    This one works fine

    RewriteRule ^airport-info-(.*)-(.*).htm$ uk-airport-information.htm?airport=$1&category=$2 [QSA,L]

    I use dashes instead of / so yours should be
    ^index\/(.*)\/(.*).shtml$.... if you want index/xyz/xyz.shtml

    Expat
     
    expat, Sep 15, 2005 IP
  10. Henny

    Henny Peon

    Messages:
    2,118
    Likes Received:
    241
    Best Answers:
    0
    Trophy Points:
    0
    #50
    hmm, no joy, i wonder what is going on....
     
    Henny, Sep 15, 2005 IP
  11. expat

    expat Stranger from a far land

    Messages:
    873
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #51
    you have

    RewriteEngine on
    Options +FollowSymLinks

    in there have you?

    expat
     
    expat, Sep 15, 2005 IP
  12. Henny

    Henny Peon

    Messages:
    2,118
    Likes Received:
    241
    Best Answers:
    0
    Trophy Points:
    0
    #52
    yes, here is my entire htaccess:

    
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^index\/(.*)\/(.*).shtml$ index.php?mode=$1&item=$2 [L]
    
    Code (markup):
     
    Henny, Sep 15, 2005 IP
  13. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #53
    ::RewriteRule ^index\/(.*)\/(.*).shtml$ index.php?mode=$1&item=$2 [L]

    Are you trying to go to

    domain.com/index/ANYTHING/ANYTHING.shtml
    or
    domain.com/ANYTHING/ANYTHING.shtml

    The code looks right if you want index/ in it. (And the script still needs to have the links changed.)

    There doesn't need to be \ before the /. Only for . and - .

    ::::;Is there a way to 301 redirect ANY call to any older style rewritten url to the new one?

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^shop/(.*)$ http://www.domain.com/$1/ [R=301,L]
    or
    RewriteRule ^whatever/$ http://www.domain.com/ [R=301,L]
     
    Nintendo, Sep 15, 2005 IP
  14. Henny

    Henny Peon

    Messages:
    2,118
    Likes Received:
    241
    Best Answers:
    0
    Trophy Points:
    0
    #54
    OK, you lost me a bit :p here is the url:

    http://www.bestamazonprices.com/index.php?mode=PCHardware&item=B0002OZXHO
    Code (markup):
    I would like it to read:

    http://www.bestamazonprices.com/index/PCHardware/B0002ozxho.shtml
    Code (markup):
    Am I doing it wrong?
     
    Henny, Sep 15, 2005 IP
  15. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #55
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^index/([^.]+)/([^.]+).shtml$ index.php?mode=$1&item=$2 [L]

    or

    RewriteRule ^index/(.*)/(.*).shtml$ index.php?mode=$1&item=$2 [L]

    Looks like you got it right. To see if you even got mod_rewrite support, try

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

    Then do to domain.com/index.shtml and your php script should show up.

    Are you on a Windows server? :D
     
    Nintendo, Sep 15, 2005 IP
  16. Henny

    Henny Peon

    Messages:
    2,118
    Likes Received:
    241
    Best Answers:
    0
    Trophy Points:
    0
    #56
    Nope, apache, and suppoedly mod rewrite via htaccess is supported. I will try the above and report back.
     
    Henny, Sep 15, 2005 IP
  17. Henny

    Henny Peon

    Messages:
    2,118
    Likes Received:
    241
    Best Answers:
    0
    Trophy Points:
    0
    #57
    These has no effect on the url

    This script with mydomain/index.shtml showed my home page
     
    Henny, Sep 15, 2005 IP
  18. Henny

    Henny Peon

    Messages:
    2,118
    Likes Received:
    241
    Best Answers:
    0
    Trophy Points:
    0
    #58
    OK, I have given up on that one for a while, time for another :p

    what do you do with the cart ID in an URL like this?

    
    cgi-bin/ecommerce/ac/agora.cgi?cart_id=1905192.84539*7z5Hx0&product=Software
    
    Code (markup):
     
    Henny, Sep 16, 2005 IP
  19. Nintendo

    Nintendo ♬ King of da Wackos ♬

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

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^cart/([^.]+)/([^.]+)\.html$ cgi-bin/ecommerce/ac/agora.cgi?cart_id=$1&product=$2 [L]

    domain.com/cart/whatever/whatever.html

    But, if it's on the same server, and the other code doesn't work, then this one probably won't work. (And only links work, not URLs generated from clicking a form button, aka shopping cart.) I'm guessing this is from the script you mentioned on that thread about CMS scripts! Good idea to make sure the URL can change before editing the script!!!
     
    Nintendo, Sep 16, 2005 IP
  20. Imran

    Imran Notable Member

    Messages:
    2,343
    Likes Received:
    191
    Best Answers:
    0
    Trophy Points:
    230
    #60
    This faq is really really helped me but Im stuck here, not able to do mod rewrite for this url
    http:// www . com/polyphonic_tones.php?mmchar22_1=Y&mmstart22_1=1&mmsection22_1=&mmphonetype22_1
    =&mmmoreinfo22_1=&mmpart22_1=&mmsearch22_1=&mmstype22_1=&mmcat22_1=&mmcountry22_1=
    is there way to do mod_rewrite for this?
    Thanks
     
    Imran, Sep 25, 2005 IP