Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    25
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Mod_rewrite question

    I am totally new to mod_rewrite. Anyone can help me with this?

    I am using a html to call for the search.php to search mysql database. For example, if I search num1, the url of the search result is shown as www.mywebsite.com/search.php.

    How do I write the RewriteRule so that it will be shown as www.myurl.com/Data/num1?

    Thank you very much.

  • #2
    New Coder
    Join Date
    Dec 2010
    Posts
    25
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Anybody could help me?


    Quote Originally Posted by toolglutton View Post
    I am using a html to call for the search.php to search mysql database. For example, if I search num1, the url of the search result is shown as www.mywebsite.com/search.php.

    How do I write the RewriteRule so that it will be shown as www.myurl.com/Data/num1?

    Thank you very much.

  • #3
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,307
    Thanks
    4
    Thanked 205 Times in 202 Posts
    If what is being searched for is coming from a form field on the HTML page you won't be able to rewrite anything to get the desired result. The server, Apache, doesn't "see" things that are entered on forms.
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    toolglutton (01-21-2011)

  • #4
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    I made a similar system. You need a script (PHP or so) to catch the form data and redirect it, like:

    PHP Code:
    header('Location: /Data/'.urlencode($_REQUEST['query']), 301);
    die(); 
    The rewrite rule you're looking for is something like:

    Code:
    RewriteRule ^Data/(.+)$            /search.php?query=$1       [L]
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog


  •  

    Posting Permissions

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