Questions & Answers

add trailing slash after removing .html extention

My website is non www, it has wordpress in subdirectory and some static webpages in the root and other subdirectory.

I want to

  1. remove .html extention from the webpages in the root and the others static webpages in subdirectory,
  2. add slash at the end,
  3. 301 redirect from non slash to URL with slash.

so it should be to

and to

The below code

  1. Is working with non slash at the end.
  2. Redirects 301 URL with slash to non.

Here's my .htaccess:

 <IfModule mod_rewrite.c>     
 Options +FollowSymLinks -MultiViews

RewriteEngine On     
RewriteBase /

#removing trailing slash
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^(.*)/$ $1 [R=301,L]

#www to non
RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?example\.com)$ [NC]
RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f     
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^([^\.]+)$ $1.html [NC,L]

#index redirect 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/     
RewriteRule ^index\.html$ [R=301,L]
RewriteCond %{THE_REQUEST} \.html     
RewriteRule ^(.*)\.html$ /$1 [R=301,L] 

Everything is ok with the wordpress, the problem is with static pages only.

2023-01-18 00:10:04 might be more appropriate
2023-01-18 00:10:04
What error are you getting when you enter in browser?
2023-01-18 00:10:04
it redirect me to
2023-01-18 00:10:04
Here's my Original link before stripping html or both of them redirect 301 to and i want to add slash at the end
Answers(0) :