SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    865
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question about pretty URLs

    This URL works perfectly in that the URL does not change in the address bar:

    http://www.oil-testimonials.com/essential-oils/7484/

    Recently I have been working on a facelift for my website, so I put all the needed files into a directory called newVersion. Now when I go to this URL:

    http://www.oil-testimonials.com/newVersion/essential-oils/7484

    Somehow the URL is no longer pretty and reverts back to the ugly format:

    http://www.oil-testimonials.com/newVersion/essential-oils.php?tID=7484

    Here are the relevant lines in my .htaccess file:

    RewriteRule ^essential-oils/([0-9]+)$ http://www.oil-testimonials.com/newVersion/essential-oils.php?tID=$1 [L]
    RewriteRule ^essential-oils/([0-9]+)/$ http://www.oil-testimonials.com/newVersion/essential-oils.php?tID=$1 [L]
    RewriteRule ^essential-oils/([0-9]+)/([a-zA-Z0-9\+]+)$ http://www.oil-testimonials.com/newVersion/essential-oils.php?tID=$1&q=$2 [L]

    Does anyone know whey I have to use the full path otherwise the RewriteRule does not work? Does it have anything to do with the fact that I'm running this .htaccess file from within a subdirectory instead of from the root?

    Thanks!
    Last edited by Stevie D; Jul 19, 2012 at 15:40. Reason: URLs delinked
    Convert your dollars into silver coins. www.convert2silver.com

  2. #2
    SitePoint Zealot maxdream01's Avatar
    Join Date
    Feb 2011
    Location
    USA
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't remember exactly but make sure you have options MultiViews or options +FollowSymLinks on in .htaccess, try both (seperatley) and see which one works.
    PHP is FUN

  3. #3
    Mouse catcher silver trophy Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,892
    Mentioned
    123 Post(s)
    Tagged
    1 Thread(s)
    I'm not sure of why it isn't working (Apache isn't my forté), but one thing to point out ... I hope this is just a development phase, and not a long-term thing. Having "newversion/" as part of a public URL is just awful. It looks so amateurish, adds a completely unnecessary layer of complexity to the URL (and an additional point of failure for people typing it in), hurts your SEO and looks completely ridiculous when you next revamp the site.

    In other words, the basic format of the URL oil-testimonials.com/essential-oils/7484/ should always point to the correct version of the page!

    Off Topic:

    PS - where you're just demonstrating a URL, please don't allow it to become hyperlinked – either leave off the http://www. at the start, or wrap it in [noparse]...[/noparse] tags.

  4. #4
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    865
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Stevie, not to worry, newVersion is just a temporary thing where I do all my testing. Once all is complete I will replace the code at the root with the code that is in /newVersion
    Convert your dollars into silver coins. www.convert2silver.com

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

    You forced the display of the redirection with the absolute (external) redirection, i.e., http://yadda-yadda. The R=301 (permanent redirection) flag will do the same thing, too, so don't use that if you need to hide your URIs.

    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

  6. #6
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    865
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    dklynn,

    When I take your advice and get rid of the full URL, my page only partially loads. Do you have any idea why? Here is what I have in my .htacess file:

    # When someone is trying to view a testimonial with this format:
    # oil-testimonials.com/newVersion/essential-oils/2657/lemon-oil-as-a-deodorant


    RewriteRule ^essential-oils/([0-9]+)/([a-zA-Z0-9\-]+)$ essential-oils.php?tID=$1 [L]
    Convert your dollars into silver coins. www.convert2silver.com

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

    The only reason I can think of is a problem with the PHP script. The only other possible reason is a default output which might happen if tID is not the correct key.

    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

  8. #8
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by busboy View Post
    dklynn,

    When I take your advice and get rid of the full URL, my page only partially loads. Do you have any idea why? Here is what I have in my .htacess file:

    # When someone is trying to view a testimonial with this format:
    # oil-testimonials.com/newVersion/essential-oils/2657/lemon-oil-as-a-deodorant


    RewriteRule ^essential-oils/([0-9]+)/([a-zA-Z0-9\-]+)$ essential-oils.php?tID=$1 [L]
    Do you reference any absolute paths in your PHP that don't match the rewrited URL?
    ictus==""


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
  •