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.
| SitePoint Sponsor |
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.
I found this:
It seems to work okay and turn www.example.com/page.html into www.example.com/page/RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+/)*([^./]+)/?$ /$2.html [L]
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.

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
Updated mod_rewrite Tutorial Article (setup, config, test & write
mod_rewrite regex w/sample code) and Code Generator
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/pageRewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^/?([a-zA-Z0-9]+)$ $1.php [L]
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/)

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).
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.Code:RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^/?([a-z]+/)?([a-z]+)/?$ $1$2.html [L]
Regards,
DK
David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
Client and (unpaid) WHB Ambassador
Updated mod_rewrite Tutorial Article (setup, config, test & write
mod_rewrite regex w/sample code) and Code Generator
Bookmarks