www.webdeveloper.com
Results 1 to 3 of 3

Thread: apache rewrite

Hybrid View

  1. #1
    Join Date
    Nov 2006
    Posts
    72

    apache rewrite

    I want to redirect

    Code:
    index.php?message=test
    to

    Code:
    index.php/message/search/test
    Now,I write .htaccess it like that

    Code:
    RewriteEngine on
    RewriteCond %{QUERY_STRING} message=^(.*)$
    RewriteRule ^(.*)$ /index.php/message/find/$1 [L]
    I call index.php?message=test and it's not redirect. How should I write htaccess file.
    Last edited by saturngod; 08-07-2009 at 01:52 AM.

  2. #2
    Join Date
    Aug 2009
    Posts
    20

    Lightbulb Why do you need to do this?

    Why do you want to rewrite the URI when you could just use the GET parameter passed in the query string? I get the feeling that your index.php file will have to parse that query string again at some point. Are you using a framework?

    I haven't tested anything, but just a quick glance gets my regex senses tingling:
    • Your RewriteCond directive uses ^ and $; those match the beginning and end of a string. They don't make sense when you're trying to capture something in the middle.
    • Why are there parentheses around the .* in your RewriteRule? I take it your backreference $1 refers to the (.*) in the RewriteCond (which is a somewhat advanced feature -- nice job).

  3. #3
    Join Date
    Aug 2009
    Posts
    20
    I wish vBulletin had an "edit" button on personal posts...

    First of all, backreferences to RewriteCond directives are preceded with %, not $. You would use %1 instead of $1.

    Also, remember that, at some point, index.php has to decode its PHP_SELF string to extract the message name. You might want to modify the original script instead.

    Here's something that works:

    RewriteEngine on
    RewriteCond %{QUERY_STRING} message=(.*)
    RewriteRule ^(.*)$ index.php/message/search/%1?

    Note the question mark at the end -- it clears out the query string. Not sure why mod_rewrite cares about that...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles