0

I'm trying to remove the .html extension from url for my website by editing the .htaccess file under the web root(public_html) directory. My server is bluehost.

The problem is that I have previous settings in the .htaccess file already for the redirecting primary domain to a subdirectory purpose.

The script is below. Also with the script i found online for hiding the extension from url.(The script doesn't work) It will be really nice if someone can help me out with the problem. Thanks.

# Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php


# BlueHost.com 
# .htaccess main domain to subdirectory redirect 
# Do not change this line. 
RewriteEngine on 
# Change example.com to be your main domain. 
RewriteCond %{HTTP_HOST} ^(www.)?qinglish.ca$ 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteCond %{REQUEST_URI} !^/qinglish_ca/ 
# Don't change the following two lines. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteRule ^(.*)$ /qinglish_ca/$1 
# Change example.com to be your main domain again. 
# Change 'subdirectory' to be the directory you will use for your main domain 
# followed by / then the main file for your site, index.php, index.html, etc. 
RewriteCond %{HTTP_HOST} ^(www.)?qinglish.ca$ 
RewriteRule ^(/)?$ qinglish_ca/index.html [L]

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
2
  • What exactly isn't working? Commented Jan 22, 2015 at 10:25
  • The .html extension still shows Commented Jan 22, 2015 at 14:40

1 Answer 1

3

Instead of your last rule you will need these rules to remove .html extensions fro all URLs:

## hide .html extension
# To externally redirect /dir/file.html to /dir/file
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]

# To internally forward /dir/file to /dir/file.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.html -f [NC]
RewriteRule ^(.+?)/?$ /$1.html [L]

Place them at same place where you have current rule to add .html extension.

Sign up to request clarification or add additional context in comments.

9 Comments

Hi sorry with the script you provided everything works perfectly, however, i just found out that my other subdirectories pages under the same domain are now having linking issues. like the link from this page stopped working. link, link. Is there anyway to fix it? @anubhava
Hi i'm not sure if i placed it right or wrong, so please go to this link and let me know, thank you:)
No the picture in the link is all the rules i have, i deleted all the rest .htaccess file from the other subdirectory folders, kept only the one in the document root, but the problem stays.
But http://www.qinglish.ca/cn/portfolio-item-02.html is just loading fine now though it didn't remove .html extension. Can you check your VirtualHost config and check what is DocumentRoot set to.
Hi I looked up some virtual host videos and really didn't understand and figured out how to check the virtual host and the document root set to...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.