I need to somehow remove the last slash in my directory URLs. For example, instead of example.com/projects/, I'd like to see example.com/projects. I have been trying many solutions with no luck so far. Here is my .htaccess file currently:Options +FollowSymLinksDirectoryIndex index.htmlRewriteEngine onRewriteCond %{HTTP_HOST} ^example.com [NC]RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]RewriteCond %{THE_REQUEST} /index\.html [NC]RewriteRule ^(.*?)index\.html$ /$1 [L,R=301,NC,NE]RewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{DOCUMENT_ROOT}/$1/index\.html -f [NC]RewriteRule ^(.+?)/?$ /$1/index.html [L]ErrorDocument 404 http://www.example.com/error404.html
Removing slash from directory URL
htaccess;url;clean urls
Presumably you are already linking to the directory URLs without the trailing slash? That is the first step.Since these are physical directories you need to tell mod_dir to not fix these URLs by appending a trailing slash. You can do this with the DirectorySlash directive near the top of your file:DirectorySlash OffThis means that you now need to manually append the trailing slash with an internal rewrite. Note that mod_dir ordinarily 301 redirects to the slashed URL, so this will have been cached by the browser. Ensure your browser cache is clear before testing.RewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{DOCUMENT_ROOT}/$1/index\.html -f [NC]RewriteRule ^(.+?)/?$ /$1/index.html [L]The main problem with this is that the first RewriteCond directive prevents directories from being rewritten, which would seem to be the opposite of what you are trying to achieve. Try the following instead:RewriteCond %{REQUEST_FILENAME} -dRewriteCond %{DOCUMENT_ROOT}/$1/index.html -fRewriteRule ^(.+?)/?$ /$1/index.html [L]ErrorDocument 404 http://www.example.com/error404.htmlAside: You should specify a root-relative URL to your error document, like:ErrorDocument 404 /error404.htmlIf you use an absolute URL Apache will trigger an external redirect to your error document (instead of an internal subrequest) which is generally undesirable.