1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

php dynamic? pages with good urls. NOT .com/php?=1, BUT .com/05-21-2012.php

Discussion in 'PHP' started by prince718, May 21, 2012.

  1. #1
    Hello. I intend on revamping my site and want to implement php. I offer photo services, and post the pics on the site. I have the main photos page with thumbnails to the specific events, then when you click on the page, you get thumbnails to all the pics from that specific event.. and i want to make it where- javascript loads the pics in a small window in the browser when clicked, or maybe just do a smaill sized popup....

    I need to make something where the pages are possibly generated. So i have http://partyprinceproductions.com/photos.html. The thumbnails to each event, and I want those thumbnails to link to generated? pages. I am still studying, and I think with some trial and error, i can get it to do the .com/php?=1, .com/php?=2, etc... But I want solid urls. Better, or should I say much much better for sharing purposes, and will help with seo down the road... so i would like .com/events/05-21-2012.php (or .html).... or maybe .com/pics/2012-21-05.php ( or .html)

    side note. I do intend on locking the site aswell... so guests have to sign in. And also plan on implementing some kind of Share box. Something like youtoube has for their videos, where you can copy the html code to share on different sites.

    Any and ALL help would be highly appreciated! Thanx
     
    prince718, May 21, 2012 IP
  2. PK-Host

    PK-Host Guest

    Messages:
    109
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #2
    I recommend you looking into mod_rewrite. With that you can make your urls look however you want

    
    Options +FollowSymLinks
    Options +Indexes
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(.*)\/$ $1.php [nc]
    PHP:
    I'm no expert but that should allow you to access any page e.g www.yourwebsite.com/about.php at www.yourwebsite.com/about/ how to do variables in urls thats a bit more complex and out of my league :p
     
    PK-Host, May 21, 2012 IP
    prince718 likes this.
  3. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #3
    For basic sites and light scripts use .htaccess to "map" out your urls.... For larger sites learn a framework... Zend Framework is a good one if you can justify the learning curve.
     
    NetStar, May 21, 2012 IP
    prince718 likes this.
  4. prince718

    prince718 Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hmmmmm. Thanx Thanx. I did see a post somewhere about the mod_rewrite.....

    As far as the .htaccess. Could you go into a little detail about what you mean by ""map" out your urls"...? Because this site, i believe is more on the simple side. So maybe I could start with this option...
     
    prince718, May 22, 2012 IP
  5. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #5
    "Mapping out your URLs" in .htaccess is using mod_rewrite. Note that to use mod_rewrite, you need to be running the Apache web server. There are equivalent techniques for other web servers (IIS for example) but you'll have to check the documentation for those.

    For mod_rewrite on Apache, you will also need to ensure mod_rewrite is activated on your server, and make sure you're able to use .htaccess files. It can vary from server to server, so if you're not sure, I'd advise checking with your webhost or your server admin.

    All mod_rewrite does is change the way the URL looks in your address bar. Using mod_rewrite you can "map" virtually any URL to any file in your document root. To get started, create a file in your public_html (or www) folder named .htaccess -- be sure the "dot" is at the beginning of the file. You may have to set your FTP client to show invisible files to be able to see it as files prefixed with a dot are "invisible".

    Open the file in your text editor and add the following lines. Note that lines beginning with a # are comments and are ignored by the server.
    
    RewriteEngine On
    
    # http://www.example.com/photos/2012-05-29 will map to http://www.example.com/photos/2012-05-29.php
    # http://www.example.com/photos/SomeAlbum will map to http://www.example.com/photos/SomeAlbum.php
    RewriteRule ^photos/(.*) /photos/$1\.php	[NC]
    
    # http://www.example.com/pics/2012-05-29 will map to http://www.example.com/photos.php?album=2012-05-29
    # http://www.example.com/pics/SomeAlbum will map to http://www.example.com/photos.php?album=SomeAlbum
    RewriteRule ^pics/(.*) /photos.php?album=$1	[NC]
    
    Code (markup):
    The URL in the browser will show example.com/photos/album while the file served from the server will be whatever rule you decide to use.

    There are a plethora of tutorials on how to use mod_rewrite. It can get fairly advanced and you can cause pages to break if the syntax is incorrect, so do some reading before you start messing around with it. Worst case scenario though, you can just delete the .htaccess file and everything will go back to normal.

    Hope this helps some.
     
    kbduvall, May 25, 2012 IP
    prince718 likes this.
  6. prince718

    prince718 Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Wow. I think thats exactly what I need. I would be doing something more like

    # http://www.example.com/photos.php?album=2012-05-29 will map to http://www.example.com/pics/2012-05-29
    OR
    # http://www.example.com/photos.php?album=2012-05-29 will map to http://www.example.com/pics/2012-05-29.php

    I am still a beginner, but what you wrote is understandable.. Now here's the thing, considering I will just create it where the folder with the albums are looped through (I guees, right?), I should be able to set it up and just upload the albums with my ftp or custom uploader and have the album names be the dates /pics/05-26-2012 (to pics/05-26-2012.php).... So, is there a way to have that automatically generated for me, or would I have to write every line for every album....? I am starting to get the feeling that the .htaccess script you just wrote will continually work :)confused:). Your help is much appreciated.
     
    prince718, May 25, 2012 IP
  7. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #7
    If you use something like this in your .htaccess in your document root (public_html, www, htdocs or whatever it is on your server):
    
    RewriteEngine On
    RewriteRule ^pics/(.*) /pics/$1.php	[NC]
    
    Code (markup):
    Then whenever a user types in yoursite.com/pics/SOME_DATE, your server will see yoursite.com/pics/SOME_DATE.php and try to serve that page whether or not that page exists. So you can upload all your 2012-05-23.php files under /pics and it will automatically be translated. Just remember that if someone does, say, /pics/2012-03-12, and there is no 2012-03-12.php file, they will get a 404.
     
    kbduvall, May 25, 2012 IP