SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Newbie Search Engine friendly URL

  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Newbie Search Engine friendly URL

    I am struggling to get the following working and was hoping someone can shed some light on where I am going wrong please.

    I have the following

    .com/catalog/toy.php

    I would like it to display as

    .com/reviews

    I have this in the .htaccess file in /catalog but no joy

    RewriteRule ^/reviews$ toy\.php$ [QSA,L]

    Thanks

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

    From too many perspectives, your mod_rewrite code is bad:
    Code:
    RewriteRule ^/reviews$ toy\.php$ [QSA,L]
    Some hosts are configured to REQUIRE that you turn mod_rewrite on before writing mod_rewrite statements.
    Code:
    RewriteEngine on
    Apache must have the mod_rewrite module enabled. Check the simple test in my signature's tutorial article if your code doesn't work - after getting it correct.

    Apache 1.x requires the / after ^ (at the DocumentRoot level) while Apache 2.x believes that it's already there and will NOT match if the / is in the regex (as you have it). If you're not sure which version of Apache you're using, ^/? will work for both.

    reviews$ must be at the end of the test {REQUEST_URI} string.

    The redirection should cause a 404 as you indicate that toy.php is located in the catalog directory.

    QSA, the Query String Appended flag, is superfluous in this case as you're not created a new query string so any pre-existing query string will AUTOMATICALLY be passed along.

    Horray! The Last flag is properly terminating your mod_rewrite statement (too many people don't know to use that!).

    Hint: Use the R=301 flag during testing so you can see the effect of your redirection and remove it for "production" to retain the reviews link.
    Code:
    RewriteEngine on
    RewriteRule ^/?reviews$ catalog/toy.php [R=301,L]
    If you have questions, please review the tutorial (with coding examples) as it's helped many members already.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Thanks very much for the explanation, you have been very helpful. This will help me greatly

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
  •