The IfModule does fix the slash problem for all links. All links get a / behind it.
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
</IfModule>
To fix the / behind folders only use and not the code above here. Does not work in ALL browsers (IE for example).
Options +FollowSymlinks -MultiViews
DirectorySlash On
I was using the following code [orginal post].
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(website.com)(:80)? [NC]
RewriteRule ^(.*) http://www.website.com/$1 [R=301,L]
RewriteRule ^files/$ files.php$1 [L]
RewriteRule ^files/([A-Za-z0-9-]+)$ files.php?sub=$1 [L]
The original link is /files.php?sub=page1
and changes to /files/
. This works fine.
But if I type /files
into the url it goes to filesfiles/?sub=page1
.
How can I make /files
(without the end slash) also go to /files/
and for the folder only.
I tried a lot of things, but I can't get it right.
<?php
// Load pages
$sub = strtolower($_GET['sub']);
//
if(strlen($sub) > 0){
if(file_exists('files/'.$sub.'.php')){
include('files/'.$sub.'.php');
}
else{
echo "<h1 class=\"titel\">Page not found.</h1>";
echo "<p>The page doesn't exist or hasn't been found.</p>";
}
}
else{
include('files/page1.php');
}
?>
page1.php loads fine to /files/ and when using the url /files it return to files/?sub=page1 page2.php is linked like /files/page2 and shows fine.
There is only a problem with the page1 if I don't want to show page1 in the url. The url like /files/page1 works fine, but I want it like /files/
domain.com/files.php?sub=page1 loads the content fine.
domain.com/files/?sub=page1 also loads the content fine.