SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    May 2008
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating nicer looking URLs

    When browsing some sites I see the links for their pages like

    "thissite/about"
    instead of

    "thissite/about,php".
    Is there an easy way to do this without creating a new folder for every single page?

  2. #2
    SitePoint Zealot FaridHadi's Avatar
    Join Date
    Nov 2008
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you are looking for is called mod_rewrite (if you are using Apache).
    Search for mod_rewrite and mod_rewrite tutorials on Google.

  3. #3
    SitePoint Member
    Join Date
    May 2008
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've got

    RewriteEngine on
    RewriteRule ^page/([^/\.]+)/?$ index!php [L]
    (index!php is index dot php but I had to remove the .)

    ..just to test it out, but when I got to whatever/page/hi it comes up with a 404.. :l

  4. #4
    SitePoint Zealot FaridHadi's Avatar
    Join Date
    Nov 2008
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might have placed the .htaccess file in the wrong directory.
    Have a look at http://www.workingwith.me.uk/article...ng/mod_rewrite and go through the examples one by one.
    mod_rewrite can be quite tricky so take your time and try to understand every step you take.

  5. #5
    SitePoint Evangelist webchalkboard's Avatar
    Join Date
    Jan 2005
    Location
    Bristol, UK
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    RewriteRule ^page/([0-9]+)$ index.php?page_id=$1 [L]

    That should work ok for taking

    http://www.site.com/page/2 and redirecting to http://www.site.com/index.php?page_id=2

    Or even simpler

    RewriteRule ^page/about$ about.php

    http://www.site.com/page/about to http://www.site.com/about.php

    Hope that's some help.

    Quote Originally Posted by aa7on View Post
    I've got



    (index!php is index dot php but I had to remove the .)

    ..just to test it out, but when I got to whatever/page/hi it comes up with a 404.. :l
    Last edited by webchalkboard; Mar 3, 2009 at 08:13. Reason: Adding more information to the post
    Websites for Sale - Sell websites in a purpose built marketplace
    Then do some Shopping

  6. #6
    Django Jedi neron-fx's Avatar
    Join Date
    Sep 2007
    Location
    Bristol/Bath, UK
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alternatively our very own DkLynn has a very good article which I think he links to in his signature which goes into detail on working with Mod-Rewrite. A very nice article indeed.

    *.... starts rummaging for the link ... *
    Neron-Fx
    Everytime a user opens Internet Explorer, a web developer dies...
    http://www.savethedevelopers.org/

  7. #7
    SitePoint Zealot
    Join Date
    Dec 2008
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    don't forget to use the right keywords when using mod_rewrite. It is pretty powerful if done right

  8. #8
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,322
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    i've found multiviews gives extensionless urls automatically:

    Options +MultiViews

    in the .htaccess. seems too easy. is that bad for some reason? seems to work well.


Bookmarks

Posting Permissions

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