SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member RileyW's Avatar
    Join Date
    Jan 2004
    Location
    Texas
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Confused w/ mod_rewrite

    Greetings,
    I have been using mod_rewrite for two months as my sub-domains.
    Code:
    Sub-domain example:
    ---------
    RewriteCond %{HTTP_HOST} sub.domain.com
    RewriteCond %{REQUEST_URI} !sub/
    RewriteRule ^(.*)$ sub/$1 [L]
    Now I would like to add something like http://domain.com/fld/add/ point to http://domain.com/index.php?op=fld&a=add. The code I tried worked before when I tested it.
    Code:
    RewriteRule ^/(.*)/(.*)/$ /index.php?op=$1&a=$2 [L]
    I get a 404 error, and then I check the error log and it says
    "[Sun Mar 14 12:00:00 2004] [error] [client 127.0.0.1] File does not exist: /home/domain/public_html/fld/add/"


    Any idea of whats the problem?
    FYI: the .htaccess file starts with
    Code:
    RewriteEngine On
    Options +FollowSymlinks
    Thanks
    Last edited by RileyW; Mar 14, 2004 at 15:15.
    QwErTy-wannabe

  2. #2
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    > RewriteCond %{HTTP_HOST} sub.example.com
    > RewriteCond %{REQUEST_URI} !sub/
    > RewriteRule ^(.*)$ sub/$1 [L]
    Hmmm,
    if you try to use:
    sub.example.com/something/containing/sub/etc
    it won't work...

    My suggestion is this:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/sub/
    RewriteRule ^(.*)$ /sub/$1 [L]

    a more optimized rule can be this, though:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC]
    RewriteRule !^sub/.*$ /sub%{REQUEST_URI} [L]

    that said, we can look at your 404.
    > RewriteRule ^/(.*)/(.*)/$ /index.php?op=$1&a=$2 [L]

    If you search these forums for posts under my user name and using ``golden rule'' you will find ``my'' mod_rewirte's golden rule,
    that's:
    Do not start a RewriteRule with a slash under a per-directory context
    per-directory context are:
    a) .htaccess
    b) Directory block within httpd.conf

    So the golden rule will say to you:
    Do not use:
    RewriteRule ^/etcetc etcetc
    but use
    RewriteRule ^etcetc etcetc


    Try to use this:

    RewriteEngine On
    RewriteRule ^([^./]+)/([^./]+)/?$ /index.php?op=$1&a=$2 [L]

    it will match all URIs as:
    something1_except_dot_except_slash/something2_except_dot_except_slash
    and
    something1_except_dot_except_slash/something2_except_dot_except_slash/

    and will internally call:
    /index.php?op=something1_except_dot_except_slash&a=something2_except_dot_except_slash



    Andrea
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  3. #3
    SitePoint Member RileyW's Avatar
    Join Date
    Jan 2004
    Location
    Texas
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Excellent

    Thanks pippo,
    I was wondering when you were going to make your rounds on the forum to answer questions, hehe. The code fix worked great, and the site runs smoothly.

    ~ Riley
    QwErTy-wannabe


Bookmarks

Posting Permissions

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