Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

A little htaccess help please

Options

Comments

  • Closed Accounts Posts: 8,478 ✭✭✭GoneShootin


    RedirectMatch might do it.

    The RedirectMatch directive is the newer of the two, and is a lot easier to work with. RedirectMatch uses a standard POSIX regular-expression-driven pattern matching and replacement engine. As a general rule, the pattern matched by <url-regex> will be replaced by the string at <new-url>. If <new-url> begins with a slash (/), then the whole path is replaced by <new-url>. If it begins with a transport protocol, such as http://, https:// or ftp:// then the whole URL is replaced by <new-url>. Below are a few examples:

    RedirectMatch permanent file.html otherfile.php

    RedirectMatch /x[12345]{1,4}/index.html http://domain.com/notfound.html

    The first of the two examples simply redirects any request for files named file.html to a file within the same directory called otherfile.php. The second example is a bit more complicated; it matches any file named index.html within a directory whose name is the letter 'x' followed by any combination of one to four of the digits 1 through 5. If you request such a file, it will redirect you to http://domain.com/notfound.html. Phew!

    Further functionality (and complications) can be added by backreferencing substrings of the matched expression. You surround the expression to be referenced in parentheses, and then use a dollar sign followed by a number (the index of the matched string from the first expression) in the place where you want to insert the string matched. It makes more sense if you look at an example:

    RedirectMatch /(.+)/([ABC]).html /otherdirectory/$1/newfiles/$2.php

    The effect of this expression is as follows:

    http://www.mydomain.tld/dir/dir2/B.html
    (becomes)
    http://www.mydomain.tld/otherdirectory/dir2/newfiles/B.php

    http://www.mydomain.tld/xyz/C.html
    (becomes)
    http://www.mydomain.tld/otherdirectory/xyz/newfiles/C.php

    Remember that in regular expression land, a period matches any character, and a plus sign means "match one or more instance of the preceding pattern, so .+ means "match one or more of any character." With that in mind, the first expression matches files named A.html, B.html or C.html found in a directory whose name is made of one or more characters. Since all directories' names are made of one or more characters, adding that part doesn't change much about which files match and which ones don't. But the information is used later on in the second expression.

    The second expression takes the name of the file and changes the .html part to .php. It also takes the name of the directory matched before and puts it in the place marked $1 in the second expression, as you can see from the examples. The $1 always refers to the first parenthesized expression, the $2 refers to the second, and so forth.

    example


  • Closed Accounts Posts: 518 ✭✭✭danbhala


    i'd use something along the lines of this
    Options  FollowSymLinks
    
    RewriteEngine On
    
    DirectoryIndex index.php
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/] )/?$ index.php?search_user=$1&search_submit=Search [L]
    


  • Closed Accounts Posts: 37 monkey junkie


    Great got it working (based on danbhala's code)

    Thank you :)


  • Closed Accounts Posts: 518 ✭✭✭danbhala


    glad to be of service :p


Advertisement