<p>I don't think this is particularly <strong>Craft CMS</strong> specific problem. Just Apache .htaccess rules in general. I would try to search for and answer of Stack Overflow. I have a strong feeling it's been answered there already.</p>

<p><a href="https://stackoverflow.com/questions/7780859/htaccess-rewrite-to-force-trailing-slash-at-the-end">https://stackoverflow.com/questions/7780859/htaccess-rewrite-to-force-trailing-slash-at-the-end</a></p>

CC BY-SA 4.0
2018-10-17T19:47:27.557Z
2018-10-17T19:55:39.400Z
2018-10-17T19:55:39.400Z
Alex Roper
<p>After redirecting a website to https environment I had the difficulty that .php/ was added to the url which resulted in double content. I have been able to get past this mistake but now I need to force a /  on in the end if the url’s does not have that yet.</p>

<p>Example</p>

<pre><code>Domainname.com/example/
</code></pre>

<p>and</p>

<pre><code>Domainname.com/example
</code></pre>

<p>Are now visible in Google. I want only the one with the /</p>

<p>Current .htaccess is:</p>

<pre><code>DirectoryIndex index.php
ErrorDocument 404 /404.html

RewriteEngine On
### START WWW &amp; HTTPS
# ensure www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

### END WWW &amp; HTTPS
RewriteBase / 
RewriteRule ^([^.?]+[^.?/])$ $1/ [R=301,L]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*[^/])/?$ /$1.php [QSA,L]

RewriteRule ^index\.php$ / [R=301,L]

#1)externally redirect "/file.php" to "/file"   
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
#2)Internally map "/file" back to "/file.php"
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [NC,L]
</code></pre>

CC BY-SA 4.0
2018-10-17T19:48:42.583Z
I'm voting to close this question as off-topic because it belongs on another site in the Stack Exchange network.
Alex Roper
CC BY-SA 4.0
2018-10-19T16:02:53.303Z
Cross-site post on Webmasters: https://webmasters.stackexchange.com/questions/118502/htaccess-please-help-getting-trailing-slash-back
MrWhite
<redirect><htaccess><https><redirection>
Forcing a / with .htaccess
# Forcing a / with .htaccess

(Asked by: username_0 on 2018-10-17)

After redirecting a website to https environment I had the difficulty that .php/ was added to the url which resulted in double content. I have been able to get past this mistake but now I need to force a /  on in the end if the url’s does not have that yet.
Example
Domainname.com/example/

and
Domainname.com/example

Are now visible in Google. I want only the one with the /
Current .htaccess is:
DirectoryIndex index.php
ErrorDocument 404 /404.html

RewriteEngine On
### START WWW & HTTPS
# ensure www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

### END WWW & HTTPS
RewriteBase / 
RewriteRule ^([^.?]+[^.?/])$ $1/ [R=301,L]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*[^/])/?$ /$1.php [QSA,L]

RewriteRule ^index\.php$ / [R=301,L]

#1)externally redirect "/file.php" to "/file"   
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
#2)Internally map "/file" back to "/file.php"
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [NC,L]

**Tags:** redirect, htaccess, https, redirection

> **Comments:**
> **username_1**: I'm voting to close this question as off-topic because it belongs on another site in the Stack Exchange network.  
> **username_2**: Cross-site post on Webmasters: https://webmasters.stackexchange.com/questions/118502/htaccess-please-help-getting-trailing-slash-back  

---

## 1 answers

### Answer by username_1 on 2018-10-17. Score: 1

I don't think this is particularly **Craft CMS** specific problem. Just Apache .htaccess rules in general. I would try to search for and answer of Stack Overflow. I have a strong feeling it's been answered there already.

<https://stackoverflow.com/questions/7780859/htaccess-rewrite-to-force-trailing-slash-at-the-end>


---

