Results 1 to 5 of 5

Thread: Mod rewrite - possible

  1. #1
    Join Date
    Dec 2006
    Posts
    3

    Default Mod rewrite - possible

    Suppose I have a subdomain 'http://sub.abc.org'

    I would like to setup a rewrite that would satisfy the following.

    1. User enters 'http://sub.abc.org/string'
    2. The server will interpret this as 'http://sub.abc.org/index.php?query=string'
    3. The url bar will display 'http://sub.abc.org/string'. The page will load based on the string submitted through the url.

    http://del.icio.us does this in some manner. It has to be possible.

  2. #2
    Join Date
    Oct 2006
    Posts
    358

    Default

    In the root directory of sub.abc.org (probably /public_html/abc/sub/) create a file named .htaccess with the following content:

    Code:
    RewriteEngine on
    RewriteRule ^([a-zA-Z]*)$ index.php?query=$1
    The "[a-zA-Z]*" part rules out the slash char so you can still do sub.abc.org/sub/folders/here without clashing with the rewrite rule. You may want to change this depending on your application.

    That should do it.

  3. #3
    Join Date
    Dec 2006
    Posts
    3

    Default

    That worked like a champ. Thank you so much.

    edit: i solved my other problem with php.
    Last edited by vatik; 12-12-2006 at 10:46 PM.

  4. #4
    Join Date
    Dec 2006
    Posts
    3

    Default

    There is a problem with this method.

    If the query contains any character not (a-z) or (A-Z), such as '?query=mr2' or '?query=dog+cat' the rewrite gets confused and results in a 404. help?

  5. #5
    Join Date
    Oct 2006
    Posts
    358

    Default

    In that case you just need a less restrictive rule, say

    Code:
    RewriteEngine on
    RewriteRule ^([^/]*)$ index.php?query=$1
    or

    Code:
    RewriteEngine on
    RewriteRule ^(.*)$ index.php?query=$1
    or

    Code:
    RewriteEngine on
    RewriteRule ^([a-zA-Z0-9_+]*)$ index.php?query=$1
    It just depends on what kind of query strings you will be receiving

    This guide is helpful:

    http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •