Mobile app version of vmapp.org
Login or Join
Bethany197

: How to remove a slash with .htaccess I have a problem, when I'm on the homepage and want to go to a page, it says this: continenten/.html on this server How can I remove the / so

@Bethany197

Posted in: #Htaccess #TrailingSlash

I have a problem, when I'm on the homepage and want to go to a page, it says this:


continenten/.html on this server


How can I remove the / so it's continenten.html and not continenten/.html?

This is my .htaccess file so far:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ .html [NC,L]

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Bethany197

1 Comments

Sorted by latest first Latest Oldest Best

 

@Alves908

You would seem to have a couple of problems. You are trying to implement extensionless URLs, but (as per your comment) you have file.html and a subdirectory called file in the same directory. Because of this mod_dir is automatically adding the slash onto the end of the URL and your .htaccess directives are copying this slash into the substitution, hence the erroneous slash in the rewritten URL (and presumably a 404).

One solution might be to simply disable slash redirects:

DirectorySlash Off


However, this might have other consequences, depending on how your site is structured. See: httpd.apache.org/docs/2.4/mod/mod_dir.html#directoryslash
Alternatively, you could change the pattern in your RewriteRule to exclude (forward) slashes as well. Although, this might also have implications if you have subdirectories, so it might need to be modified further:

RewriteRule ^([^/.]+)$ .html [NC,L]


I've simply changed your backslash to a (forward) slash. I'd also question whether you need the . (dot) in the character class? (The dot does not need to be backslash escaped in a character class, it carries no special meaning here.)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme