SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member edpudol's Avatar
    Join Date
    Oct 2004
    Location
    philippines
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help:how To Do The Redirect

    Hello guys,

    Will you please help me to solve this problem. How to create a mod rewrite for this problem.

    i have the following url

    Code:
    locate.php?a=numbers; //combination of numbers 0-9
    Instead of that url, I made it search engine friendly,

    the new url now is

    Code:
    location/numbers.html; //combination of numbers 0-9
    I then create a mod re-write

    Code:
    RewriteEngine  on
    RewriteRule ^location/([0-9-]*).html$  locate.php?a=$1 [L,NC]
    The above mod rewrite work fine... but my problem is

    When someone access directly the file

    locate.php?a=numbers; //combination of numbers 0-9

    How can I redirect someone else who open the locate.php to the search engine friendly url?

    example locate.php?a=12 -> location/12.html

    Thanks in advance
    Visit us at lexorsoft.net , if you need SEO related services

  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)
    Hi ed!

    Welcome to SitePoint!

    First, please allow me to comment on your mod_rewrite code:

    Code:
    RewriteEngine  on
    RewriteRule ^location/([0-9-]*).html$  locate.php?a=$1 [L,NC]
    That allows location/.html so the first question is whether locate.php can handle a null entry.

    The second question is whether it can handle location/-.html, too.

    The third question is WHY you're using the No Case flag on a {REQUEST_URI} variable. Please understand that it would cause LoCaTiOn/.HtMl to match and, while that may not cause a problem with $1 (that wasn't mentioned above), it's completely and totally inappropriate. Having said, that, though, if you ever try to match the {HTTP_HOST} variable which is NOT case sensitive, that's where you (logically) MUST use the No Case flag.

    My preferred version of your code would be:

    Code:
    RewriteEngine  on
    RewriteRule ^location/([0-9-]+).html$  locate.php?a=$1 [L]
    
    OR 
    
    RewriteRule ^location/([0-9]+(-[0-9]+)*).html$  locate.php?a=$1 [L]
    which would require at least one digit then zero or more -digit sets.

    As for creating "loopy code" redirecting from the actual link to your NEW FORMAT then back to the actual link, I'll let you read the tutorial article linked in my signature for the code. Of course, if you still have problems, post what you have and I'll help you get to the solution.

    Sorry, I do this to prevent having script kiddies come and ask for free coding ... and to be sure SitePoint members actually learn something so they can help others in the future.

    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
  •