SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Dawson
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Want to make /page.html become /page/

    I've been trying to make my address show up as www.example.com/page/ instead of www.example.com/page.html

    Can anyone help me do this with .htaccess or any other way that might work better.

  2. #2
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Dawson
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found this:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^([^/]+/)*([^./]+)/?$ /$2.html [L]
    It seems to work okay and turn www.example.com/page.html into www.example.com/page/

    The problem is when I try and do it in a folder such as www.example.com/folder/page.html I get a not found page.

    Anyhelp ihelp in finding the problem would be amazing.

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    NOTB,

    The basic question (extensionless URLs) is covered by example in my signature's tutorial Article. IMHO, you're using regex which is too open and have neglected the $1 variable (the reason for your 404) in that mash-up. Have a read then get back with questions, please.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Dawson
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^/?([a-zA-Z0-9]+)$ $1.php [L]
    I used that code from you site, and it worked for example.com/page but I still get a 404 when I try example.com/folder/page

    Any ideas, I'm completley lost here.

    Also, I noticed I get a 404 if I have backslash on the page (ex: example.com/page/)

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    NOTB,

    The code above actually checks that the requested filename (without extension) is a php file - in DocumentRoot. You actually got pretty close with your attempt (although [^/] is too wide open for me - I prefer [a-z] for lowercase letters to know that other nonsense will not creep in).
    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^/?([a-z]+/)?([a-z]+)/?$ $1$2.html [L]
    That will catch the FIRST level subdirectory and sent it, if it exists, along with the filename with .html appended. The key here is to capture the subdirectory name (and /) and preceed the filename with that atom.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •