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 19
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts

    Exclamation please advise on mod rewrite (i think)

    Hi All,

    not sure if this is mod rewrite or not?

    i'm sure i've read somewhere that you can display urls in a different 'format' that how it is supposed to be?

    for example i have a url which is something like
    Code:
    www.mywebsite.com/results.php?category=dvd&item=item_name&id=item_id
    is it possible to have it display something like
    Code:
    www.mywebsite.com/dvd/item_name/item_id.php
    basically i have thousands of 'virtual' pages which are all created depending on the product searched for so i dont actually have all these pages saved on the server as they are created from one file. so im not sure if it is possible to display /dvd/item_name/item_id.php because there is no such directory.

    hope this makes sence?
    cheers
    Luke

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    http://www.workingwith.me.uk/article...ng/mod_rewrite

    might help. Only glanced at it but seemed to mention everything you need to know from what I saw

  • Users who have thanked Nightfire for this post:

    LJackson (04-29-2010)

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    Hi mate,

    so it is called mod_rewrite sweet, i wasn't sure...

    that looks exactly like what i am looking for thanks so much

    Luke

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    ok i have spent a while researching mod_rewrite and have found what i need to do but it doesnt seem to be working

    i have my url as it is now
    Code:
    http://www.mywebsite.com/price_finder2.php?store=The%20Simpsons:%20Greatest%20Hits
    and i want it to be
    Code:
    http://www.mywebsite.com/The%20Simpsons:%20Greatest%20Hits.php
    so i have added this to my .htaccess file
    Code:
    RewriteEngine on
    RewriteRule ^([^/\.]+).php$ price_finder2.php?store=$1 [L]
    but nothing has changed?

    have i done it right?
    thanks

    Luke

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    What do you mean nothing has changed? If you go to this url: http://www.mywebsite.com/The%20Simps...est%20Hits.php does it work? What you won't automatically direct users to the new url if that is what you were wanting.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    Hi Mate,

    ok i obviously dont understand this mod_rewrite lark .

    lets say i have a list of products on a page each with a link to the price_results2.php page, but also the name and category are being passed in the url so the page knows which info to display so here is one of those urls

    http://www.mysite.com/price_finder2....0Hurt%20Locker

    now what i am trying to acheive is when the user clicks on the link for this item the url should show http://www.mysite.com/The%20Hurt%20Locker.php

    but with my current code it doesnt it still shows the original url?

    hope that explains it a bit better? not sure why its not changing the url though.

    here is the tutorial i followed
    Code:
    5. Description – Your actual URL is http://example.com/index.php?page=hello  which you want to see as http://example.com/hello.htm
    Solution – Place the following lines in your .htaccess file
    
    RewriteEngine on
    RewriteRule ^([^/\.]+).htm$ index.php?page=$1 [L]
    cheers
    Luke
    Last edited by LJackson; 05-01-2010 at 06:32 PM.

  • #7
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    still unable to solve this. All the tutorials i've followed dont seem to work

    anyone have any ideas please?
    thanks

  • #8
    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 LJackson View Post
    still unable to solve this. All the tutorials i've followed dont seem to work

    anyone have any ideas please?
    thanks
    The links you see in the output generated by any scripts will remain as they always were, unless you rewrite any local, (from your servers viewpoint), links to the new format. The htaccess side of things is only interpreting those links from the perspective of an incoming request from a client.The links in your page source require a PHP solution. You need to bollocks the links up via some function or suchlike before you output the page source to the client.


    Edit: What reason are you wanting this for, btw? Is it because you do like the other link format or is it for some supposed S.E.O benefit, (of which there is none).
    Last edited by MattF; 05-01-2010 at 12:48 PM.

  • #9
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    Hi Mate, thanks for your reply,

    just think the url looks much cleaner doing it this way, im sure the user would much prefere to see a url like
    Code:
    www.mywebsite.com/dvd/the_hurt_locker.php
    instead of
    Code:
    www.mywebsite.com/price_results2.php?category=dvd&product=the_hurt_locker
    then users would then beable to just change the film name to what ever and it should load up that page? i see many sites including twitter, and facebook to name a few that do it. so are they using some php script? or going via the .htaccess route? sorry still dont really understand it totally

    many thanks
    Luke
    Last edited by LJackson; 05-03-2010 at 11:04 AM.

  • #10
    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 LJackson View Post
    Code:
    www.kernow-connect.com/dvd/the_hurt_locker.php
    instead of
    Code:
    www.kernow-connect.com/price_results2.php?category=dvd&product=the_hurt_locker
    then users would then beable to just change the film name to what ever and it should load up that page? i see many sites including twitter, and facebook to name a few that do it. so are they using some php script? or going via the .htaccess route? sorry still dont really understand it totally
    Pretty much what happens is that the first link above doesn't actually work other than in a virtual sense. You need to rewrite your scripts, somehow, to output that link though, even though it leads to nothing as such. That's where the htaccess rewrite rules come in. When someone uses that link, it rewrites it internally to point to the correct link, which is the second link above. So, the user sees the format in the first link but is actually using the second link, (the valid one where your scripts are concerned), as far as the server is concerned.

  • #11
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    ok i understand what you mean now

    is it a difficult job to do?
    i know of a php script which i might beable to edit for my needs to fix the virtual urls but i have no idea about the htaccess rewrite. a nice little job for me to start

    thanks for the help and info mate
    appreciate it

    Luke

  • #12
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    The hardest part is changing the link structure in your scripts. If it has a templating engine, you have a central point for changing them. If not, depends on how your software is structured. The rewriting part is merely regex matching, so should be the easiest part. If it's an off the shelf type system you're using, I'd check to see if there's already a URL prettifying, (the person who coined that term ought be shot, honestly), mod out there for it.

  • #13
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    Hi Mate,

    ive spent a bit of time chaniging the format of my links and i have it setup so that it will send users to a virtual url e.g

    PHP Code:
    http://www.kernow-connect.com/dvd/the_hurt_locker.php 
    which doesnt exist but the url which is actually valid is this

    PHP Code:
    http://www.kernow-connect.com/price_finder2.php?category=dvd&product=The%20Hurt%20Locker 
    but im not sure how to setup the mod rewrite so that all virtual urls are linked to a url like above.

    not sure how it works but there are thousands of products which could be requested and each one needs to redirect to the valid url ???

    again not sure how this all works mate, sorry
    Cheers
    Luke

  • #14
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Regex.

  • #15
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    hi mate, unfortunatly that is something i know nothing about have looked on google but find it very difficult to follow

    i have read a tutorial type thing which gives this code to put into htaccess
    Code:
     RewriteEngine On  
       
     RewriteCond %{SCRIPT_FILENAME} !-d  
     RewriteCond %{SCRIPT_FILENAME} !-f  
       
     RewriteRule ^users/(\d+)*$ ./profile.php?id=$1  
     RewriteRule ^threads/(\d+)*$ ./price_finder2.php?id=$1  
       
     RewriteRule ^search/(.*)$ ./search.php?query=$1
    i have tried changing it but i dont really know what im doing?

    any ideas please
    thanks
    Luke


  •  
    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
    •