/    Sign up×
Community /Pin to ProfileBookmark

.htaccess issue: trailing slash added, but not working for subdirectory

I have found a well working .htaccess code on the internet that removed the .html extension and adds a trailing slash at the end of the URL.

However, when I link to a site in a subdirectory, it does not work, the subdirectory automatically gets erased in the URL, so the page is not loaded.

Here is my .htaccess code:

[CODE]
AddHandler application/x-httpd-php71 .php

AddDefaultCharset utf-8

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
[/CODE]

I also have this same .htaccess in said subdirectory.

Does anybody have an idea how I can fix this issue?
Thanks for any help!

to post a comment

3 Comments(s)

Copy linkTweet thisAlerts:
@rootOct 10.2018 — Have you tried an online tool for testing the regex parts of the rules.

In fact, search for Online HTACCESS test and you will find some sites that can test the thing for you, you play with the code.

Debugging info
1 AddHandler application/x-httpd-php71 .php This line is not supported by our tool.
2 AddDefaultCharset utf-8 This line is not supported by our tool.
3 RewriteEngine on RewriteEngine was now turned on
4 RewriteCond %{HTTP_HOST} ^example.com [NC] This rule was not met.
5 RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC] This rule was not met.
6 RewriteCond %{REQUEST_FILENAME} !-d This condition was met.
7 RewriteCond %{REQUEST_FILENAME}.html -f This test string is not supported: %{REQUEST_FILENAME}.html
8 RewriteRule ^([^/]+)/$ $1.html This rule was not met.
9 RewriteCond %{REQUEST_FILENAME} !-f This condition was met.
10 RewriteCond %{REQUEST_FILENAME} !-d This condition was met.
11 RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,5}|/)$ This rule was not met.
12 RewriteRule (.*)$ /$1/ [R=301,L] This rule was not met.
Copy linkTweet thisAlerts:
@SantuzzoauthorOct 10.2018 — Thank you very much! I'm still pretty new to all of this, and to be honest, I just did google searches to find the .htaccess code and I don't even understand the code.

I will look for .htaccess testing sites to see if I can figure this out.

Thanks again, I appreciate your help!
Copy linkTweet thisAlerts:
@SantuzzoauthorOct 10.2018 — Edit: for clarification I may add that the subdirectory I'm talking about is part of the same website, so some parts of it I would like to keep in a subdirectory just for keeping things organized.
×

Success!

Help @Santuzzo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...