SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast magnam's Avatar
    Join Date
    Jun 2006
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mod_Rewrite help

    Hello there!

    I am having a small issue that I am hoping one of you could help me fix quick.

    Here are the contents of .htaccess:
    Code:
    Options +FollowSymLinks
    Options +Indexes
    RewriteEngine On
    
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^(.*)/(.*)$ index.php?id=$1&name=$2 [L]
    When I navigate to the following, it works
    http://www.site.com/1234/hello

    When I navigate to the following, it does NOT work:
    http://www.site.com/1234/hello/

    It seems to be messing up when I have ANY forward slashes at the end...

    Any ideas? thanks!

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

    Add a /? before the end anchor.

    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 Enthusiast magnam's Avatar
    Join Date
    Jun 2006
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, that sort of fixes the problem however when I add another directory for example:

    http://www.site.com/1234/hello/hehe

    The name variable gets replaced with "hehe" and doesn't stay as "hello"

    index.php?id=$1&name=$2

    I wish id would stay as $1 and name would stay as $2...

  4. #4
    SitePoint Enthusiast magnam's Avatar
    Join Date
    Jun 2006
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, when the url is requested with a forward slash at the end, it messes up the variables. I am echoing the ID and NAME variables on the page.

    When the url ends with a forward slash those variables get messed up.

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

    When you change the target URI like that, you are forcing yourself to write another mod_rewrite statement (to capture the second value for the redirect). Best to start over with a "specification" that is thought out and covers all the redirections you require.

    IMHO, **AVOID** trailing slashes on your URIs as that not only affects the mod_rewrite but the relative links in the redirection's target file.

    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
  •