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
    #561
    It's not now. Empty your cache.

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^nixism\.com [NC]
    RewriteRule ^(.*)$ http://www.nixism.com/$1 [R=301,L]
     
    Nintendo, Apr 11, 2007 IP
  2. bLaZ3n

    bLaZ3n Banned

    Messages:
    259
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #562
    your amazing.. thanks!
     
    bLaZ3n, Apr 11, 2007 IP
  3. bobbyr

    bobbyr Peon

    Messages:
    232
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #563
    Is it a good code with this one?
    Options Indexes +FollowSymLinks Includes +ExecCGI
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^site\.com
    RewriteRule ^(.*)$ http://www.site.com/$1 [R=permanent,L]

    And is it better to change it directly in apache for google ex:
    Apache as follows:

    for "site.com":

    Redirect permanent / http://www.site.com/

    or to do it in .htaccess ?

    Bobby
     
    bobbyr, Apr 20, 2007 IP
  4. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #564
    .htaccess is much easior to edit.
     
    Nintendo, Apr 20, 2007 IP
  5. KevinJB

    KevinJB Peon

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #565
    Here is my .htaccess file:

    However this rule apparently redirects anything to index.php, even capital letters and symbols... What did I do wrong?
     
    KevinJB, Apr 21, 2007 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #566
    Post an example of the original URL and how you want it.
     
    Nintendo, Apr 21, 2007 IP
  7. Mystique

    Mystique Well-Known Member

    Messages:
    2,579
    Likes Received:
    94
    Best Answers:
    2
    Trophy Points:
    195
    #567
    Ah... so this is the only thread where Nintendo replies...

    I was wondering why he seems to ignore other threads requesting similar help :rolleyes:
     
    Mystique, Apr 21, 2007 IP
  8. KevinJB

    KevinJB Peon

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #568
    I'm trying to redirect ANY request that contains only lowercase letters, numbers, and / or the characters:
    to /index.php

    For example:
    example.com/foo/bar-3.0
    would be redirected,
    example.com/foO/bar-3.0
    would not be. But this:
    ^[a-z0-9\./-]+$
    Code (markup):
    seems to match any string, as far as I can tell... what did I do wrong?

    [edit]

    Ok, it looks like the problem is in this part:
    \.
    Code (markup):
    If I remove that it works (except if there is a '.' in the URL obviously), so it appears that the '.' isn't getting escaped like I thought it was- how do I escape special characters then?
     
    KevinJB, Apr 22, 2007 IP
  9. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #569
    Afaik, within the [] notation, you do not need to escape metacharacters - other than the obvious ones that could be confused ([ ] and possibly -, depending on position).

    Have you tried without escaping the period? I can't imagine why still escaping it anyway should cause problems but other than it looks perfect.
     
    rodney88, Apr 23, 2007 IP
  10. coby

    coby Peon

    Messages:
    159
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #570
    I have searched the forum but i didnt find the answer maybe i didnt search very good. Sorry if this question posted again.

    I want to redirect my vbulletin forum from a dir www.domain.com/vbulletin to www.domain.com

    Can i do that with mod_rewrite?

    Thanks
    coby
     
    coby, Apr 24, 2007 IP
  11. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #571
    Options +FollowSymLinks +Indexes
    RewriteEngine on
    RewriteBase /
    RewriteRule ^vbulletin/(.*)$ http://www.domain.com/$1 [R=301,L]
     
    Nintendo, Apr 24, 2007 IP
  12. KevinJB

    KevinJB Peon

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #572
    Thanks for your help, I removed the backslash that was escaping it but still no luck (Expression: ^[a-z0-9/.-]+$ ).
     
    KevinJB, Apr 24, 2007 IP
  13. coby

    coby Peon

    Messages:
    159
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #573
    Thanks Nintendo!

    I tried this one but it didnt work.
    Where do i have to put this one? On root or in subdir?
    Also i have an index.html which does the automatic redirection to the /vbulletin dir on root. Is this causing any problems?

    After some thinking... I realised that my completed question would be:
    How can i create permanent redirection to the vbulletin dir and rewriting the url showing only the domain name using .htaccess?

    I have to say that i tried permanent redirection from a tutorial using htaccess but after that all my addon domains on server stopped working, so i used index.html... :(
     
    coby, Apr 26, 2007 IP
  14. Nintendo

    Nintendo ♬ King of da Wackos ♬

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

    for just taking vbulletin/ out of the URL.

    Is the index.html using meta redirect in the file? That wouldn't effect it.
     
    Nintendo, Apr 26, 2007 IP
  15. RaZoRLeGaCy

    RaZoRLeGaCy Well-Known Member

    Messages:
    189
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #575
    RaZoRLeGaCy, Apr 26, 2007 IP
  16. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #576
    Nintendo, Apr 27, 2007 IP
  17. RaZoRLeGaCy

    RaZoRLeGaCy Well-Known Member

    Messages:
    189
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #577
    RaZoRLeGaCy, Apr 27, 2007 IP
  18. coby

    coby Peon

    Messages:
    159
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #578
    I created it in the root but nothing happened...
    When i load the site www.domain.com the page starts reloading with no output.
    Maybe its the index.html file that has the redirection on meta.(as you mentioned)
    I deleted the index.html on root to see what happens and i saw the index of my server. I clicked on some dirs but reloads on the root.

    Whats wrong?
    Can we fix this?

    Thanks.
     
    coby, Apr 27, 2007 IP
  19. kgtrip

    kgtrip Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #579
    Hi Nintendo,

    It seems when I use more than 9 parameters at my RewriteRule, the server confuses and refers $10 as to $1 and a zero afterward, and for $11 as $1 and 1 afterward
    So if $1 gets "hi" value,$10 would become "hi0" is there a way overcoming this problem?
     
    kgtrip, May 4, 2007 IP
  20. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #580
    I've enver tried having more than nine, so I'm not sure why it does that.

    Do you have it like

    whatever.php?wacko=$1&more=$2&soon=$3
    or
    whatever.php?$1=$2&$3=$4&$5=$6 ?
     
    Nintendo, May 5, 2007 IP