SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Smart programmer silver trophy M.Zeb Khan's Avatar
    Join Date
    Jan 2004
    Location
    Luton, Beds
    Posts
    1,792
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with mod reqwrite.

    Hi,

    Can you help me passing a domain name in the url, so when the users enter myscript.com/sitepoint.com

    it should redirect to:
    search.php?output=nice&query=sitepoint.com

    I have the following in my htaccess but the problem is, its not passing the dots:

    RewriteEngine On
    RewriteRule ^([a-zA-Z0-9]+)$ search.php?output=nice&query=$1

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    ZK,
    Quote Originally Posted by M.Zeb Khan View Post
    Output: search.php?output=nice&query=sitepoint.com

    I have the following in my htaccess but the problem is, its not passing the dots:
    If you're not passing the dot character, add it to the character range, i.e., [a-zA-Z0-9] => [a-zA-Z0-9.]

    Think about that, though, 'cause that will also match search.php (it's ALMOST as bad as using (.*)!) and cause a loop. What's the difference? The extension that you're willing to accept.

    There are three ways to correct this problem:

    1. Add a "marker" to the link which will then designate that it's to be redirected to search.php, i.e.,
    Code:
    RewriteRule ^link-to-([a-zA-Z0-9.]+)$ search.php?output=nice&query=$1 [L]
    2. Specify the domain extensions that you will accept: .com, .org, .whatever, i.e.,
    Code:
    RewriteCond %{REQUEST_URI} (\.com|\.org|\.whatever)$
    RewriteRule ^([a-zA-Z0-9.]+)$ search.php?output=nice&query=$1 [L]
    3. Specify the file extensions that you will NOT redirect to search.php: .php, .js, .css, i.e.,
    Code:
    RewriteCond %{REQUEST_URI} !(\.php|\.js|\.css)$
    RewriteRule ^([a-zA-Z0-9.]+)$ search.php?output=nice&query=$1 [L]
    It's all in specifying your requirements for the mod_rewrite statements.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    Smart programmer silver trophy M.Zeb Khan's Avatar
    Join Date
    Jan 2004
    Location
    Luton, Beds
    Posts
    1,792
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks David, it worked !

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    ZK,



    While I'm sure that every one would work, other members might like to know which one you selected.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    ZK,



    While I'm sure that every one would work, other members might like to know which one you selected.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    Smart programmer silver trophy M.Zeb Khan's Avatar
    Join Date
    Jan 2004
    Location
    Luton, Beds
    Posts
    1,792
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi dk,

    well, I used the third one and its working perfect here www.grabMyWhois.com

    thanks again

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    Thanks Z-K! I hope that will help others.

    Thanks!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •