SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems with mod rewrite code.

    Hi:

    I am new at mod_rewrite and I am trying to rewrite some urls on my site.,

    I have a plesk server, and at present my mod_rewrite is not working.

    My question is do I have to turn on mod_rewrite in plesk servers?

    Do I have to modify the php.ini?

    At present I am using this in my .htacess file


    RewriteEngine On

    AddType x-httpd-php .php .htm .html

    AddHandler application/x-httpd-php .php .htm .html

    php_flag register_globals on


    RewriteRule ^findahome/(homes-[0-9]+).html$ /findahome/listing_details.php?listing_id=$1 [L]

    Is anything wrong with the snippet above?

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

    First, WELCOME to SitePoint's Apache forum!

    Plesk? I thought they were only on IIS servers, not Apache servers. Okay, let's assume I'm wrong about Plesk's residence and get to your two mod_rewrite statements:
    Code:
    RewriteEngine On
    # should be 'on' (without the quotes) but I don't think Apache really cares
    
    RewriteRule ^findahome/(homes-[0-9]+).html$ /findahome/listing_details.php?listing_id=$1 [L]
    # fine for Apache 2.x; Apache 1.x requires the start anchor to be followed by a /, i.e., ^/,
    # and, if you're not sure which you're using, ^/? will work for both
    Otherwise, nothing wrong (unless you're getting a 500 error which would indicate that you do not have mod_rewrite enabled).

    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
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks

    I changed


    RewriteRule ^findahome/(homes-[0-9]+).html$ /findahome/listing_details.php?listing_id=$1 [L]

    To


    RewriteRule ^/findahome/(homes-[0-9]+).html$ /findahome/listing_details.php?listing_id=$1 [L]

    I have also tried

    RewriteRule ^/?findahome/(homes-[0-9]+).html$ /findahome/listing_details.php?listing_id=$1 [L]

    None of these worked for me. I am using $_GET['rewrite'] to let me know if the rewrite is successful or unsuccessful.

    These changes did not work for me.

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

    The leading / varies between Apache 1.x and Apache 2.x (the regex with ^/? covers both cases but you should know which version you're using).

    $_GET['rewrite'] will NOT return a value because:

    1. The key you're passing is listing_id, not rewrite

    AND

    2. By creating a query string, you're killing any previous query string (unless you use the QSA flag) so $_GET['rewrite'] cannot exist.

    One way to see errors like this is to use another flag, the R=301, which forces Apache to display the new URI. When you view that, you can see that the new {REQUEST_URI} is listing_details.php?listing_id={homes-digit(s)} and not listing_details.php?rewrite={whatever}. BTW, you really should just capture the digital value for the value of the listing_id with code like (FOR Apache 2.x):
    Code:
    RewriteEngine on
    RewriteRule ^findahome/homes-([0-9]+)\.html$ findahome/listing_details.php?listing_id=$1 [R=301,L]
    ... but remove the R=301 and comma after you're satisfied that the redirection works for you!

    As for echo() the $_GET['rewrite'] value, better to use print_r($_GET) as you'd also see that 'rewrite' is not present but listing_id is (with the value of homes-{digit(s)}). Always best to use the tools you have correctly!

    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
  •