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
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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.