SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to redirect to my php script using htaccess

    Hi

    I have gone over and over this but I can not get it to work.

    I am trying to match this:

    http://villarentfethiye.simpg.net/17...iyerental.html

    and send it to:

    http://simpg.net/info1.php?a=17

    So I am using:

    Code:
    Options +SymLinksifOwnerMatch 
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^[.+].simpg.net/[0-9]+-[\.0-9_-a-z]+\.html$ [NC]
    RewriteCond %{HTTP_HOST} !^www.simpg.net$ [NC]
    RewriteRule ^[\.0-9,-a-z]+\.simpg.net/([0-9]+)-[\.0-9_-a-z]+\.html$ http://simpg.net/info1.php?a=%1 [NC,QSA,L]
    But it is not working.

    Because this first block is not catching the incoming url,
    my second block gets it and sends it to the wrong page.

    My second block should only match:

    http://villarentfethiye.simpg.net/

    And re-direct to : http://simpg.net/info2.php?a=villarentfethiye

    It uses:

    Code:
    RewriteCond %{HTTP_HOST} ^(.+).simpg.net$ [NC]
    RewriteCond %{HTTP_HOST} !^www.simpg.net$ [NC]
    RewriteRule ^.*$ http://simpg.net/info2.php?a=%1 [NC,QSA,L]
    This second block works - BUT it should not be excepting
    any url with data coming after "simpg.net" ... but it does.

    Because when the first block fails, the second is doing
    a re-direct ( but to the wrong page )

    Can anyone see where I have gone wrong ?

    Thanks.


    .

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Hi Jekko!

    First, you are in need of some information about how to correctly write code for mod_rewrite. Therefore, you might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    http://villarentfethiye.simpg.net/17-vacationvillasfethiyerental.html => http://simpg.net/info1.php?a=17

    WHY in the world would you use villarentfethiye as a subdomain? Does it even exist? Unless you REALLY need it, the first thing I would do is strip useless information from the URL (so you can actually hide the link with the query string). Then the code would be trivial:

    Code:
    # .htaccess in DocumentRoot
    
    # strip useless domain information
    RewriteCond %{HTTP_HOST} !^simpg\.net$ [NC]
    RewriteRule .? http://simpg.net%{REQUEST_URI} [L]
    
    # Redirect to deliverable link
    RewriteRule ^([0-9]+)-[a-z]+\.html$ info1.php?a=$1 [L]
    Please note that the {HTTP_HOST} variable does not contain a / nor a URI.

    If you follow the above code, you'll KNOW why your code was not working, i.e., {HTTP_HOST} and the subdomain you captured clearly did not contain digits.

    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


Tags for this Thread

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
  •