title: Redirect with .htaccess not working correctly when missing / in the end
body: <p>I've <strong>Wordpress</strong> site with <strong>WPML</strong> installed. I've done 2 things recently:</p>
  
  <ul>
  <li>Move HTTP only to HTTPS only</li>
  <li>Move <a href="http://domain.pl">http://domain.pl</a> to <a href="https://domain.xyz">https://domain.xyz</a> (English)</li>
  <li>Move <a href="http://domain.pl/pl">http://domain.pl/pl</a> to <a href="https://domain.pl">https://domain.pl</a> (Polish)</li>
  </ul>
  
  <p>This is done to improve SEO. However while I got that working without much problem using:</p>
  
  <pre><code> # BEGIN HTTPS
   &lt;IfModule mod_rewrite.c&gt;
   RewriteEngine On
   RewriteCond %{SERVER_PORT} ^80$
   #RewriteCond %{HTTPS} !^on$
   #RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
   RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
   &lt;/IfModule&gt;
   # END HTTPS
   # BEGIN WordPress
   &lt;IfModule mod_rewrite.c&gt;
   RewriteEngine On
   RewriteBase /
   RewriteRule ^index\.php$ - [L]
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule . /index.php [L]
   &lt;/IfModule&gt;
  
   # END WordPress
  </code></pre>
  
  <p>In <strong>apache.conf</strong> file <code>ServerName domain.xyz, ServerAlias domain.pl www.domain.pl</code> and so on. I'm having problems with most of my old blog posts that are around the internet in different forms. For example: </p>
  
  <ul>
  <li>This little entry <a href="http://domain.pl/email-address-policy/">http://domain.pl/email-address-policy/</a> redirects properly to <a href="https://domain.xyz/email-address-policy/">https://domain.xyz/email-address-policy/</a> </li>
  <li>This little entry <a href="http://domain.pl/powershell-write-host">http://domain.pl/powershell-write-host</a> doesn't. It simply goes to <a href="https://domain.pl/powershell-write-host">https://domain.pl/powershell-write-host</a> which is 404 and that's it. </li>
  </ul>
  
  <p>It seems that last <strong>/</strong> is making huge difference. </p>
  
  <p>I've planned to add all redirects in even direct form 1 to 1 to new domain but since it's partially working, partially not I'm kind of lost... and I am not sure how I could translate them correctly. </p>
  
  <p>EDIT:</p>
  
  <p>I've tried multiple options, even one that supposedly rewrites all links to end with / and it still fails.</p>
  
  <pre><code># BEGIN HTTPS
  &lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  RewriteBase /
  #RewriteCond %{SERVER_PORT} ^80$
  #RewriteCond %{HTTPS} !^on$
  #RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
  #RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
  #RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
  #RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
  RewriteCond %{HTTPS} !^on$
  #RewriteRule (.*) https://evotec.xyz/$1 [R=301,L]
  #RewriteRule (.*) https://%{SERVER_NAME%}/$1 [R=301,L]
  #RewriteCond %{REQUEST_FILENAME} !-f
  #RewriteCond %{REQUEST_URI} !(.*)/$
  #RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1/ [L,R=301]
  #RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !(.*)/$
  RewriteCond %{REQUEST_FILENAME} !\.(gif|jpg|png|jpeg|css|js)$ [NC]
  RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1/ [L,R=301]
  
  
  &lt;/IfModule&gt;
  # END HTTPS
  </code></pre>
  
  <p>Another update:</p>
  
  <ul>
  <li><a href="https://domain.xyz/url-is-here">https://domain.xyz/url-is-here</a> - works correctly</li>
  <li><a href="https://domain.xyz/url-is-here/">https://domain.xyz/url-is-here/</a> - works correctly</li>
  <li><a href="https://domain.pl/url-is-here">https://domain.pl/url-is-here</a> - doesn't work, isn't convered to <a href="https://domain.xyz/url-is-here/">https://domain.xyz/url-is-here/</a></li>
  <li><a href="https://domain.pl/url-is-here/">https://domain.pl/url-is-here/</a> - convers correctly to <a href="https://domain.xyz/url-is-here/">https://domain.xyz/url-is-here/</a></li>
  </ul>
  
  <p>So it's not entirely not working for all slash vs non-slash. It's more about translation of some sort that doesn't happen if it points to old domain.</p>
  
  <p>I've tried using Redirect Checker to see how it works (on proper example) but I can't make any meaning from it. </p>
  
  <ul>
  <li>Check of <a href="http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1">http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1</a></li>
  </ul>
  
  <blockquote>
    <p><a href="http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1">http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1</a> 301
    Moved Permanently
    <a href="https://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1/">https://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1/</a>
    301 Moved Permanently
    <a href="https://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1/">https://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1/</a>
    200 OK</p>
  </blockquote>
  
  <ul>
  <li>Check of <a href="http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1/">http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1/</a></li>
  </ul>
  
  <blockquote>
    <p><a href="http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1/">http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1/</a> 301
    Moved Permanently
    <a href="https://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1/">https://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1/</a>
    200 OK</p>
  </blockquote>
  
  <ul>
  <li>Check of <a href="https://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1">https://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1</a></li>
  </ul>
  
  <blockquote>
    <p><a href="https://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1">https://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1</a>
    404 Not Found</p>
  </blockquote>
  
  <p>The more options I try the weirder it gets. While the RedirectChecker seems to be showing one thing ... browser is behaving a bit different and doesn't work for the first entry anyways causing 404 straight away</p>
  
  <p>Edit:</p>
  
  <p>If I leave only "Wordpress" data following is true:</p>
  
  <ul>
  <li><a href="http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1">http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1</a>
  gets 404 <a href="http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1">http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1</a> exactly as is</li>
  <li><a href="http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1/">http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1/</a> gets <a href="https://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1/">https://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1/</a></li>
  <li><a href="https://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1">https://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1</a> gets 404 exactly as is</li>
  </ul>
  
  <p>It only works properly if i use the correct/new domain then all works properly:</p>
  
  <ul>
  <li><a href="https://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1">https://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1</a> </li>
  <li><a href="https://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1">https://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1</a></li>
  <li><a href="http://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1">http://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1</a></li>
  <li><a href="http://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1/">http://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1/</a> </li>
  </ul>
  
  <p>I guess if I can't redirect it, i will leave it as it is and just give up. </p>