I’ve been working on removing the .html extension in the address bar, in other words change /test.html to /test, using htaccess code, but I can’t find the code to do it.
I wonder if I have to have an /index.html file, but I tried the methods below on index.html and couldn’t get /index.html to /index . In the case of index.html I don’t want “index” either, instead from /index.html to just /.
Assuming at least one of the methods below is correct, what might I be missing that would make it not work in my test folder. I have a folder labeled test and inside I have index.html (with simple, working webpage code) and test.html (with the same code as index.html) and an htaccess file.
I’ve found many methods but none work. In case it matters, I tried the code below with an without rewritebase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\\.]+)$ $1.php [NC,L]
[How to remove .php, .html, .htm extensions with .htaccess](http://www.sicanstudios.com/how-to-remove-php-html-htm-extensions-with-htaccess/)
--
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.html [L,QSA]
[How to remove file extensions from URLs | dave dash](http://davedash.com/2006/07/26/how-to-remove-file-extensions-from-urls/)
--
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html?q=$1 [L,QSA]
[How to remove file extensions from URLs | dave dash](http://davedash.com/2006/07/26/how-to-remove-file-extensions-from-urls/)
-----
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\\.html -f
RewriteRule ^(.*)$ $1.html
[Remove File Extension Using htaccess | Web, Mobile Development](http://www.blog.highub.com/apache/http-server/remove-file-extension-using-htaccess/)
------
RewriteRule ([a-zA-Z0-9]+)/?$ /$1.html [L]
[Removing file extensions with .htaccess [Archive] - bluehostforum.com](http://www.bluehostforum.com/archive/index.php/t-9964.html)
---------------------
RewriteCond /%{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-\\s]+)/$ /$1.php
[Remove File Extention from URLs](http://css-tricks.com/snippets/htaccess/remove-file-extention-from-urls/)
-----
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^([^.]+)\\.php$ $1 [L]
[remove html and/or PHP extensions in URL - CSS-Tricks Forums](http://css-tricks.com/forums/discussion/3814/remove-html-and-or-php-extensions-in-url/p1)
--------------
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\\.html -f
RewriteRule ^(.*)$ $1.html
[How to remove file extensions using .htaccess | Free Script Installation Service](http://www.free-installations.info/threads/how-to-remove-file-extensions-using-htaccess.2302/)
--------------------
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\\.]+)$ $1.php [NC,L]
[Plain Text Passwords: Remove HTML and PHP File Extensions using .htaccess](http://blog.spruce.it/2011/01/remove-file-extensions-html-and-php.html)
If it does that I’d say that you requested “samplepage.html” instead of just “samplepage”. Did you? If so, wasn’t it the whole point to rid of the .html?
ScallioXTX,
I see what you’re saying, you’re correct that I wasn’t going to /index and /samplepage.
Unfortunately, and without the google code, when I request
/index I get a 404 error and no change to the address in the address field.
When I request
/index.html the page comes up and no change to the address
Same for /samplepage and /samplepage.html.
I used ctrl F5 throughout to make sure caching wasn’t getting in the way.
ScallioXTX,
I got it.
The RewriteBase / line was causing the problem.
I would have found the problem when I was testing for RewriteBase but I had myself distracted when I was testing /samplepage.html instead of /samplepage
Somehow I had it in my head that going to /samplepage.html would change automatically to /samplepage, like a redirect.
Someone pointed out to me that sometimes an htaccess file at a higher level can cause problems with a lower level htaccess and that having both these lines in this sequence
RewriteEngine Off
RewriteEngine On
ScallioXTX,
I found this code on another Sitepoint page and from the context I thought it would eliminate the problem and result in /page/ or /page but page.html wouldn’t exist.
I could change index.php to index.html but I really have no idea what to put in for “pagename”. Maybe just a forward slash or nothing ?
That seems to easy to be correct. Even if it is correct will it apply to all .html pages or just index?
what will happen? It’s still active since it’s now a go between.
I think I’m going to not remove the .html, there’s no way to remove .html without causing seo problems. I thought htaccess could be used to acknowledge /page and without the browsers and search engines knowing the existence of /page.html. It doesn’t look like this is possible.
ScallioXTX,
I think the solution is, if your site is not about html, don’t use htaccess and instead use .htm (25% less information (no L) than html. Simce Google uses only the first 65 or so characters of an adresss, just make sure your address is 65 or more characters before the extension.
I think
/1-234-567-…65.htm
is much more seo advantageous than
/1word-2word
meaning that while having your adress end with no / and no extension seems to be the most advantageos for seo, it’s not true if the address with no / and no extension is short when compared to an address that exceeds in length google’s reach to the extension.
I think I’d like to see some sources where you got that info. TBH what you’re saying makes no sense to me whatsoever (and is actually more appropriate for a discussion in the SEO forum than here. Maybe you should start a thread there?).