.htaccess file problems

Discussion in 'Apache' started by rj87uk, Apr 14, 2007.

  1. #1
    Hi All,

    Before I ask I would like to let you all know I am not tech and have no clue about Apache or the .htaccess file.

    I have one main .htaccess file in my root folder that redirects Non www. requests to www. requests so that it is always http://www.example.com.

    Ok, I have a directory within my website lets call it "/example/". That also has a .htaccess file that does some re writing for a script I did not write.

    The problem is within this directory the redirect from the non www. to the www. does not work, I guess the .htaccess file in the "/example/" folder stops the main one from working in this folder.

    How would i add in the code that would do the redirect but not break the script? Here is the .htaccess file:

    Options +FollowSymlinks
    RewriteEngine on
    
    RewriteRule ^([^/\.]+)/?$ /example/index.php?page=regions&r=$1 [NC]
    
    RewriteRule ^example/search/?$ /example/index.php?page=search [NC]
    
    RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /example/index.php?page=towns&r=$1&t=$2 [NC]
    
    RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /example/index.php?page=show&r=$1&t=$2&n=$3&id=$4 [NC]
    
    RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /example/index.php?page=show&r=$1&t=$2&n=$3&id=$4&s=$5 [NC]
    
    Code (markup):
    So, how do I change this so that it will always redirect from http://example.com/example/blah/ to http://www.example.com/example/blah/

    Any ideas and also any other information I need to provide?

    One confused Guy - RJ
     
    rj87uk, Apr 14, 2007 IP
  2. Nintendo

    Nintendo ♬ King of da Wackos ♬

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

    RewriteEngine on
    Options +FollowSymlinks
    RewriteCond %{HTTP_HOST} ^DOMAIN\.com [NC]
    RewriteRule ^(.*)$ http://www.DOMAIN.com/$1 [R=301,L]

    RewriteBase /
    RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ example/index.php?page=show&r=$1&t=$2&n=$3&id=$4&s=$5 [NC]
    RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ example/index.php?page=show&r=$1&t=$2&n=$3&id=$4 [NC]
    RewriteRule ^([^/\.]+)/([^/\.]+)/?$ example/index.php?page=towns&r=$1&t=$2 [NC]
    RewriteRule ^([^/\.]+)/?$ example/index.php?page=regions&r=$1 [NC]
    RewriteRule ^example/search/?$ example/index.php?page=search [NC]

    and dump the .htaccess file in the directory.
     
    Nintendo, Apr 14, 2007 IP
    rj87uk likes this.
  3. rj87uk

    rj87uk Active Member

    Messages:
    283
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    60
    #3
    rj87uk, Apr 15, 2007 IP
  4. rj87uk

    rj87uk Active Member

    Messages:
    283
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Hi All,

    Got it - Just added /example/ to this line:

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

    And that has worked!

    Great Work - Thanks nintendo! Some green for you :)
     
    rj87uk, Apr 15, 2007 IP