Posted By

brent-man on 12/01/07


Tagged

url php htaccess clean


Versions (?)

Who likes this?

23 people have marked this snippet as a favorite

iTony
jonhenshaw
skywalker
SmpleJohn
Zidizei
cjurczak
sindrom
Nix
wortell
pster
nb109
Hollow
love
silentbob84
heatherk
scottwf
g33kish
bobbym245
jfoy
voove
clac
ringo380
tux-world


Clean URL


 / Published in: PHP
 

.htaccess:

RewriteEngine On

RewriteBase /

images.php, browse.php, index.php

RewriteRule ^(images|browse|index)(/.*)?$ $1.php

above can obviously be expanded GoDaddy users add this to the beginning of your htaccess or you will throw an error

Options +MultiViews +FollowSymLinks

make sure you wait about 5-10 minutes after uploading the revised .htaccess, for some reason, GoDaddy takes a few minutes to revise the .htaccess
  1. <?php
  2.  
  3. $urlArray = explode("/",$_SERVER["REQUEST_URI"]);
  4. $url_what = $urlArray[count($urlArray)-1];
  5.  
  6.  
  7. if($url_what == 'home') {
  8. // rather than index.php?act=home, url would be index/home
  9. displayHome();
  10. }elseif($url_what == 'contact'){
  11. // rather than index.php?act=contact,url will be index/contact
  12. displayContact();
  13. }elseif($url_what == 'calendar'){
  14. // rather than index.php?act=calendar,url will be index/calendar
  15. displayCalendar();
  16. }elseif($url_what == 'about'){
  17. // rather than index.php?act=about,url will be index/about
  18. displayAbout();
  19. }else
  20. //if $url_what doesn't exist, display home
  21. writeHome();
  22.  
  23. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Nix on September 27, 2008

Nice one! Thanks :)

Posted By: brent-man on September 28, 2008

No problem!

You need to login to post a comment.