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.

pretty URL's

Discussion in 'PHP' started by mbaldwin, Aug 30, 2010.

  1. #1
    mbaldwin, Aug 30, 2010 IP
  2. Wolf Security

    Wolf Security Peon

    Messages:
    78
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    As far as I know, no.
     
    Wolf Security, Aug 30, 2010 IP
  3. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #3
    You can use PHP only if it is in this format:

    www.yourdomain.com?site/1345/341

    You need the question mark, otherwise it is not possible unless you use mod rewrite.
     
    ThePHPMaster, Aug 30, 2010 IP
  4. mbaldwin

    mbaldwin Active Member

    Messages:
    215
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    95
    #4
    Thanks,
    I was afraid of that.

    Michael
     
    mbaldwin, Aug 30, 2010 IP
  5. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
  6. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #6
    In apache, this is done in rewrite url/mod.. I don't see any reason why you shouldn't use it unless you don't have apache in your server - though some http server offers some kind of url redirection
     
    Rainulf, Aug 30, 2010 IP
  7. Gray Fox

    Gray Fox Well-Known Member

    Messages:
    196
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
  8. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #8
    Rainulf, Aug 31, 2010 IP
  9. Gray Fox

    Gray Fox Well-Known Member

    Messages:
    196
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #9
    No, I actually tried it. Joomla for instance has an option to do that if there isn't mod_rewrite available. After that you must parse the parameters using $_SERVER['PATH_INFO']
     
    Gray Fox, Aug 31, 2010 IP
  10. . Jordan .

    . Jordan . Guest

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I've wondered this too. There must be a way to do this without mod_rewrite. Otherwise how are the clean url extensions for vBulletin and SMF ect doing it?
     
    . Jordan ., Aug 31, 2010 IP
  11. mbaldwin

    mbaldwin Active Member

    Messages:
    215
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    95
    #11
    I was hopeing to find a way without apache rewrite so the script can be ran on different webservers without any issues.
     
    mbaldwin, Sep 1, 2010 IP
  12. Jumperrentals

    Jumperrentals Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I would suggest you create a sub domain for your URL. You can you other URL shortening services too, but the sub domain is the best in my opinion.
     
    Jumperrentals, Sep 1, 2010 IP
  13. IMfighter.com

    IMfighter.com Peon

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    you need to make your script 404 error script and parse $_SERVER['REQUEST_URI']
     
    IMfighter.com, Sep 1, 2010 IP
  14. ndevendra

    ndevendra Member

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #14
    Here's the complete rewrite rule for you: www.yourdomain.com/site.php?mid=1345&uid=341. For this, you need to have apache mod_rewrite enabled. Let me know if you have problems in the rewrite rule.
    
    RewriteEngine On
    RewriteRule ^(.*)/(.*)[^\/]$ site.php?mid=$1&uid=$2 [L]
    Code (markup):
     
    ndevendra, Sep 2, 2010 IP
  15. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #15
    As above this is the only way, if mod_rewrite is not enabled, although the url may not look so pretty, its adequate enough for SEF urls , don't let the part about creating a .htaccess file confuse you, its nothing to do with mod_rewrite.

    Some scripts have an option to enable mod_rewrite if its available on the hosts server, so perhaps you could do that and incorporate the above if its not, there's today very few servers that don't run apache so its really not that big of an issue and besides, some have an alternative to mod_rewrite.
     
    MyVodaFone, Sep 2, 2010 IP
  16. RectangleMan

    RectangleMan Notable Member

    Messages:
    2,825
    Likes Received:
    132
    Best Answers:
    0
    Trophy Points:
    210
    #16
    IMHO you shouldn't worry about it. Pretty URLs aren't as important as you think.

    Great example is DP which doesn't use them.
     
    RectangleMan, Sep 2, 2010 IP
  17. mbaldwin

    mbaldwin Active Member

    Messages:
    215
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    95
    #17
    ndevendra,
    Thanks for that. That gives me a starting place. I will be needing at least 4 urls to rewrite for the one site, so how could I tell them apart in the reWriteRules?
    urls would be like

    http://www.domain.com/site.php?id=1234&par=abc-123
    http://www.domain.net/site/234/abc-123

    http://www.domain.com/spinner.php?id=321&par=abczz
    http://www.domain.com/spinner/321/abczz


    http://www.domain.com/banner.php?id=111&par=abc153
    http://www.domain.com/banner/111/abc153
    http://www.domain.com/banner/111.jpg

    The par is optional

    Thanks,
    Michael
     
    mbaldwin, Sep 2, 2010 IP
  18. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #18
    From the example you will still write in the top section of the appropriate file:
    
    $data[0] = whatever var is been use in this file 
    $data[1] = whatever var is been use in this file 
    $data[2] = etc...
    $data[3] = 
    
    PHP:
    and then your .htaccess file will contain
    
    <FilesMatch "^site$"> 
      <  ForceType application/x-httpd-php >
    </FilesMatch> 
    <FilesMatch "^spinner$"> 
      <  ForceType application/x-httpd-php >
    </FilesMatch> 
    <FilesMatch "^banner$"> 
      <  ForceType application/x-httpd-php >
    </FilesMatch> 
    
    PHP:
    So those file names can be phrased without having to use the .php extension.

    I guess in each of the files you will have a simple " if check mod_enabled, 1 or 0 to use this or run with mod_rewrite. Some kind of database check against or to read a config file looking for a setting yes or no etc...
     
    MyVodaFone, Sep 3, 2010 IP
  19. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #19
    olddocks, Sep 8, 2010 IP
  20. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #20
    Can be done by manipulating your custom error 404 file.
     
    danx10, Sep 8, 2010 IP