Htaccess: Redirects for Write In File Types

I have this .htaccess code for removing.html from web address

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

But when you type in “.html” next to what the code above removed, the “.html” stays. I read somewhere that google interprets the two addresses (one without and one with “.html”) as two separate pages.

Elswhere I had a slash problem to solve and used

RedirectPermanent /xyz/
and it works fine
RedirectPermanent /xyz.html
does not work, causes a 404 error.

So how do you deal with typed in file types that you don’t want to show after the typer hits enter/go/whatever ?

Thanks much,


What sort of slash problem?

Now that I think about it, an SEO site said google may think of slash ending and no slash ending might be thought of as different web pages, /xyz a different page than /xyz/ .

If you see this as a problem, you should use canonical URLs.

1 Like

I do use canons, but canons don’t stop google from seeing 2 different pages of the same thing, do they? Even so, I’d still like to have more than one way to circumvent write in addresses. Can you unwrite a typed in file type (.html) ?

I believe that is the whole point of canonical links. Did you read the article?
They can be used in conjunction with 301s.

Conjunction means together. I have the canonical, just need the 301.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.