Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New Coder
    Join Date
    Aug 2008
    Posts
    77
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Question Dynamic to Static URL in PHP

    Hi!
    I'm trying to convert my site's dynamic URLs for the past 2 weeks but to no avail, I've tried several different ways but it doesn't seem to work.

    My main requirement is that I want my dynamic URLs, for example, ...
    http://www.domain.com/item_details.p...cy=USD&iid=600

    To be shown as ...
    http://www.domain.com/item_details-l...D-iid_600.html

    Instead of using slashes ( / ) and being shown as ... (which is the problem in all the examples I found through Google) ...
    http://www.domain.com/item_details/l...D/iid_600.html

    If the slashes are used then all my images and included files stop working. So it is better for me to use underscores ( _ ) or hyphens ( - )

    I can make the underscores/hyphens based URL work with the following .htaccess :

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    rewriterule ^item_details-([^-]+)-([^&]+)\.html$ /item_details.php?language=$1&currency=$2&iid=$3 [L]

    </IfModule>

    But the final problem which I'm still facing is that I don't know how to receive the values/variables for "language", "currency" and "iid" to use them on the item_details.php page.

    Can someone please help?

    Thank you very much!

    - Xeirus

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Is there a specific reason for you wanting to break the URI's from their natural format?

  • #3
    New Coder
    Join Date
    Aug 2008
    Posts
    77
    Thanks
    23
    Thanked 0 Times in 0 Posts
    MattF,
    I am doing this for SEO reason.

    - Xeirus

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by xeirus View Post
    MattF,
    I am doing this for SEO reason.

    - Xeirus
    Is there actually any factual proof that doing so makes the blindest bit of difference though, with regards to S.E.O? Take this forum, for example. By the current supposed S.E.O standards, the dynamic URI's which are used on here should penalise this forum quite notably. Search engine statistics and S.E.R.P's will offer quite a different viewpoint though.

    Btw, I'm not trying to digress from the point of your post here, but merely trying to suggest that concentrating more on your sites content and popularity could be far more useful than breaking a standard system, just to adhere to something which I've, (personally), never seen backed up by any proven, factual proof.

  • #5
    New Coder
    Join Date
    Aug 2008
    Posts
    77
    Thanks
    23
    Thanked 0 Times in 0 Posts
    MattF,
    I understand what you're saying. I have tried to explain the same to my bosses but they won't believe me and insist on getting this done.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    The variables will be accessed the same was as before; the only thing the mod_rewrite will do is alter the appearance of the url itself. Since you're mapping it back to the proper variables here: '/item_details.php?language=$1&currency=$2&iid=$3', the language, currency and iid will all still exist within the $_GET['language'], $_GET['currency'], and $_GET['iid']. Unless I'm completely misunderstanding something here.....
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #7
    New Coder
    Join Date
    Aug 2008
    Posts
    77
    Thanks
    23
    Thanked 0 Times in 0 Posts
    Fou-Lu,
    Thank you for your reply.

    I'm trying to get variables back as :
    PHP Code:
       if (!isset($_GET['language'])) {
           
    $language 'en';
       }
       elseif (isset(
    $_GET['language'])) {
           
    $language $_GET['language'];
       }
       if (!isset(
    $_GET['currency'])) {
           
    $currency 'USD';
       }
       elseif (isset(
    $_GET['currency'])) {
           
    $currency $_GET['currency'];
       }

       
    $iid $_GET['iid']; 
    But it doesn't seem to work....

    Can you please help?

    Thank you.

    - Xeirus.

  • #8
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by MattF View Post
    Is there actually any factual proof that doing so makes the blindest bit of difference though, with regards to S.E.O? Take this forum, for example. By the current supposed S.E.O standards, the dynamic URI's which are used on here should penalise this forum quite notably. Search engine statistics and S.E.R.P's will offer quite a different viewpoint though.

    Btw, I'm not trying to digress from the point of your post here, but merely trying to suggest that concentrating more on your sites content and popularity could be far more useful than breaking a standard system, just to adhere to something which I've, (personally), never seen backed up by any proven, factual proof.
    Good point. Google "Dynamic to Static URL in PHP", which is the title of this thread and this thread already comes up Number 6 on the first page after one hour.. With results like that a URL rewrite to improve SEO is totally useless.

    http://www.google.com/#hl=en&source=...8f9588018abe0f




    ----
    Last edited by Len Whistler; 03-22-2010 at 11:48 PM.
    Leonard Whistler

  • #9
    New Coder
    Join Date
    Aug 2008
    Posts
    77
    Thanks
    23
    Thanked 0 Times in 0 Posts
    Len Whistler,
    You're right and so is MattF but like I mentioned, I wish, my bosses would understand what you just said!

    - Xeirus.

  • #10
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Have you tried just dumping the $_GET array to output to see what it contains?

  • #11
    New Coder
    Join Date
    Aug 2008
    Posts
    77
    Thanks
    23
    Thanked 0 Times in 0 Posts
    MattF,
    Just tried as you suggested but still keeps throwing out this error:
    Error retrieving Item Content from database!
    Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

    - Xeirus

  • #12
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    I think the penny has just dropped, (and hopefully someone will correct me if I'm wrong). If you're using the new style links in your pages, there won't be any $_GET vars because your webserver is using a 404 handler for the request, hence the info you require will be in the $_SERVER array. You'll need to use the likes of parse_url and such to strip the info you require from that. I believe $_SERVER['REQUEST_URI'] will contain the info you need to parse.

    Btw, you really ought to be checking your vars before running a DB query that will obviously fail. It sounds like you're running the query regardless of whether any required input is there or not.

  • #13
    New Coder
    Join Date
    Aug 2008
    Posts
    77
    Thanks
    23
    Thanked 0 Times in 0 Posts
    MattF,
    Yes, I just tried that and here's what I get from $_SERVER['QUERY_STRING'] ....
    language=language€cy=en-currency_USD-iid_424&iid=
    Completely confusing for my brain's little PHP knowledge area! LOL ... and look at that unknown character, don't know where that came from!

    And here's what I get from $_SERVER['REQUEST_URI'] ...
    /item_details-language_en-currency_USD-iid_424.html

    This one looks much better!
    Please tell me where do I go from here as I don't know how to parse, break or use this info to get my variables back?

    Thank you!

    - Xeirus

  • #14
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by Len Whistler View Post
    Good point. Google "Dynamic to Static URL in PHP", which is the title of this thread and this thread already comes up Number 6 on the first page after one hour.. With results like that a URL rewrite to improve SEO is totally useless.
    I'm personally of the line of thought that it serves no purpose other than prettifying the links in the address bar. In all this time, no matter how much people bang on about it being important for S.E.O, I've never seen anything to suggest that it has any effect, and can't say that any of the supposed experts have ever proven that it does either. At the end of the day, a URI is a URI, regardless of appearance. I personally just class it as merely a money making scheme, (for those so-called experts), or just the current fad for everyone else, but nothing more.


    p.s: xeirus, we're not questioning your ongoing question/requirement here, but rather just having a sub conversation within your thread. Hope you don't mind?

  • #15
    New Coder
    Join Date
    Aug 2008
    Posts
    77
    Thanks
    23
    Thanked 0 Times in 0 Posts
    MattF,
    Not at all. In fact, it is useful for me as I will try to show this conversation between you and Len Whistler, to my bosses as a proof to make them believe that I (just a kid when it comes to PHP) am not being lazy or anything, but you experienced coders say the same!

    - Xeirus.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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