Jump to content

.htaccess remove file extension


erme

Recommended Posts

Basically trying to remove the .html file extension from my files.

 

My site structure is as follows:

 

www.site.com/about.html

www.site.com/folder/index.html

www.site.com/folder/page.html

 

and want:

 

www.site.com/about/

www.site.com/folder/

www.site.com/folder/page/

 

 

I found this while searching:

 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

 

But it doesn't work for pages within the folder directory.

 

Many thanks

Link to comment
https://forums.phpfreaks.com/topic/246258-htaccess-remove-file-extension/
Share on other sites

Update:

 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

 

This basically works for

www.site.com/folder/

and www.site.com/folder/page

 

but I get an access forbidden when trying to access

www.site.com/folder/page/

(adding the forward slash at the end)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.