FAQ: mod_rewrite, 301 redirects, and optimizing Apache.

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

  1. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #581
    Backreferences can only go up to $9 and in most cases this is sufficient.

    I imagine you can get around this with using extra rewrite rules although I've never tried. The first rewrite rule can do the first 8 substitutions and pass the remainder into $9. Repeat as many times as needed.
     
    rodney88, May 5, 2007 IP
  2. coby

    coby Peon

    Messages:
    159
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #582
    Am i still looking for a solution... I would be glad if you could help me Nintendo.
    Thanks.
     
    coby, May 6, 2007 IP
  3. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #583
    See if you can even get mod_rewrite.

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

    domain.com/.htaccess with the index.html file being there. Then domain.com/wacko.html should show the same thing as index.html, if you do have mod_rewrite.
     
    Nintendo, May 7, 2007 IP
  4. coby

    coby Peon

    Messages:
    159
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #584
    Its working Nintendo.
    So it must be supported from my host...
    Now any suggestions?
    Thanks for your time.
     
    coby, May 7, 2007 IP
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #585
    If that works, then just changing the last line to

    RewriteRule ^vbulletin/(.*)$ http://www.domain.com/$1 [R=301,L]

    should do it, if /vbulletin/ is the actual directory name! I once did the same thing, except I moved my boards to another domain.
     
    Nintendo, May 7, 2007 IP
  6. THanhNGuyen

    THanhNGuyen Peon

    Messages:
    23
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #586
    THanhNGuyen, May 8, 2007 IP
  7. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #587
    If your server does not already accept anything.domain.info and show the same content as www.domain.info, you also need to create a wildcard dns entry and possibly a wildcard serveralias.

    Try this, in domain.info/.htaccess

    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.domain\.info$ [NC]
    RewriteRule .* member.php?member=%2 [L,QSA]
     
    rodney88, May 8, 2007 IP
  8. coby

    coby Peon

    Messages:
    159
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #588
    Thanks but the same thing is happening... Looping.
    As i was reading some posts i thought that maybe i asked the wrong question.
    I dont want exactly a redirection. I want a url masking.
    When i go to the domain.com/vbulletin on the address bar will show domain.com.
    Is this the same question i asked before? (rewrite=masking)
    Sorry for that...
     
    coby, May 8, 2007 IP
  9. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #589
    Options +FollowSymLinks +Indexes
    RewriteEngine on
    RewriteBase /
    RewriteRule ^([^.]+)$ vbulletin/$1 [L]

    If you got anything else on the site, it'll be messed up.

    Options +FollowSymLinks +Indexes
    RewriteEngine on
    RewriteBase /
    RewriteRule ^([^.]+)$ member.php?member=$1 [L]

    If you got anything else on the site, it'll be messed up.
     
    Nintendo, May 8, 2007 IP
    coby likes this.
  10. THanhNGuyen

    THanhNGuyen Peon

    Messages:
    23
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #590
    Thanks, it works

    Thanh Nguyen
     
    THanhNGuyen, May 8, 2007 IP
  11. coby

    coby Peon

    Messages:
    159
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #591
    Thanks for helping me Nintendo.
    I think the best solution is to move my forum on the root...
    Reputation added.
     
    coby, May 8, 2007 IP
  12. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #592
    If you got any of the pages indexed, then you'll want to use that 301 redirect code.
     
    Nintendo, May 8, 2007 IP
  13. apachehtaccess

    apachehtaccess Guest

    Messages:
    82
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #593
    Thats pretty interesting, I've never seen more than 9 either.. Why don't you just limit your parameters to 9? You could always combine stuff like instead of:

    whatever.php?wacko=$1&more=$2&soon=$3
    whatever.php?combo=wacko-$1--more-$2--soon-$3&combo2=
     
    apachehtaccess, May 10, 2007 IP
  14. LittlBUGer

    LittlBUGer Peon

    Messages:
    306
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #594
    I, for the life of me, can't get this url rewriting to work at all on my downloads site. I've tried so many different variations I can't even count them all. Can someone please try to help me? I know everything is OK with Apache so it's something I'm doing. Here's what I have for my .htaccess file now:

    
    Options +FollowSymLinks +Indexes
    RewriteEngine on
    RewriteBase /downloads/
    RewriteRule ^index/cid/(.*)/ /index.php?cid=$1 [L]
    RewriteRule ^index/cid/(.*) /index.php?cid=$1 [L]
    RewriteRule ^index/dlid/(.*)/ /index.php?dlid=$1 [L]
    RewriteRule ^index/dlid/(.*) /index.php?dlid=$1 [L]
    RewriteRule ^index/ACT/(.*)/id/(.*)/symid/(.*)/sess/(.*)/ /index.php?ACT=$1&id=$2&symid=$3&sess=$4 [L]
    RewriteRule ^index/ACT/(.*)/id/(.*)/symid/(.*)/sess/(.*) /index.php?ACT=$1&id=$2&symid=$3&sess=$4 [L]
    
    Code (markup):
    Site: http://downloads.littlbuger.info

    Thanks. :)
     
    LittlBUGer, May 11, 2007 IP
  15. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #595
    Post an example of the original URL, and how you want it. A directory and sub-domain are two different things.
     
    Nintendo, May 11, 2007 IP
  16. LittlBUGer

    LittlBUGer Peon

    Messages:
    306
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #596
    OK, Sure. For the categories on my site, the links now are like:

    http://downloads.littlbuger.info/index.php?cid=46

    And I want them like:

    http://downloads.littlbuger.info/index/cid/46

    The downloads/file description link now is like:

    http://downloads.littlbuger.info/index.php?dlid=576

    And I want them like:

    http://downloads.littlbuger.info/index/dlid/576

    And finally the actual download link to download each file is like:

    http://downloads.littlbuger.info/in...mid=576&sess=54822da15dab2e7155b1a2171150081b

    And I want them like:

    http://downloads.littlbuger.info/index/ACT/dl/id/575/symid/576/sess/54822da15dab2e7155b1a2171150081b

    Or possibly with a .htm extension at the end instead of just a directory structure, or maybe even just one large file, who knows. The above was what I was trying to do with my first post though. And yes, this is a subdomain. Thanks for your help! :)
     
    LittlBUGer, May 11, 2007 IP
  17. Nintendo

    Nintendo ♬ King of da Wackos ♬

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

    Options +FollowSymLinks +Indexes
    RewriteEngine on
    RewriteBase /
    RewriteRule ^index/ACT/dl/id/([^.]+)/symid/([^.]+)/sess/([^.]+)$ index.php?ACT=dl&id=$1&symid=$2&sess=$3 [L]
    RewriteRule ^index/dlid/([^.]+)$ index.php?dlid=$1 [L]
    RewriteRule ^index/cid/([^.]+)$ index.php?cid=$1 [L]

    Even better would be with out the session IDs. Google hates those!!
     
    Nintendo, May 12, 2007 IP
  18. LittlBUGer

    LittlBUGer Peon

    Messages:
    306
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #598
    Yes, I enabled the session IDs in my downloads script due to some serious leeching issues of my files and it seems to have helped, but then again, if it really hurts me as far as SEO goes, I may turn that off.

    As for the rewrites, no go. I tried that and it still didn't work. Is there some configuration that could be preventing this on my server? I know that Apache is processing the .htaccess files as I use them elsewhere with other rules and they work just fine. Thanks so much for your help. :)
     
    LittlBUGer, May 12, 2007 IP
  19. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #599
    Do a little test

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

    should make

    subdomain.domain.com/wacko.html

    show the index page. If that simple test doesn't work, nothing will.
     
    Nintendo, May 12, 2007 IP
  20. LittlBUGer

    LittlBUGer Peon

    Messages:
    306
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #600
    Strange... that doesn't work. I mean, it doesn't work for my main site, http://downloads.littlbuger.info when I put it into the .htaccess file in that subdomain folder, but if I add it to the main/root domain .htaccess file (among other things already in there) where http://www.littlbuger.info is, it works fine. Must be something with the subdomain or subfolder, I'm not sure. I'll look into it, but until then, any suggestions? Thanks. :)
     
    LittlBUGer, May 13, 2007 IP