SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Dec 2011
    0 Post(s)
    0 Thread(s)

    mod rewrite - redirect problem

    I have created a simple dynamic website with php and I am having trouble making my URL structure search engine friendly.
    What I am trying to do is redirect links like this
    HTML Code:
    to this (including a trailing backslash)
    HTML Code:
    I have spent ages searching for a solution and found the below is the only one that actually lets the new URL work but I can't redirect it.
    It seems to be backwards to every other solution I have seen, when I add R=301 into the rule it redirects the nice url to the long version.
    RewriteEngine On
    RewriteRule ^([^/\.]+)/$ /index.php?page=$1 [L]
    So in short the two problems I have with this are:
    1. It doesn't actually redirect the URL, it just allows both version to work.
    2. If I tried to use the new url without the trailing backslash
    HTML Code:
    it will just bring up the 404 page. It should redirect to the page with a trailing slash.

    Any help will be much appreciated
    Many thanks

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    19 Post(s)
    3 Thread(s)

    What've you attempted was not a bad effort but I'd REALLY advise not mimicing directories (trailing /'s) as that introduces an incorrect directory level in the path for your relative links.

    If you're assured that your "animals" will always be lowercase characters, I'd use
    RewriteEngine on
    RewriteRule ^([a-z]+)$ index.php?page=$1 [L]

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts