Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I am using cPanel to build a website and I am not sure how to take the .html or .php file extension off my webpages. Usually I will use a python framework and I do the routing manually but I am not sure how to do it with cPanel. I saw something about using .htaccess but I am not sure what I would need to put in there. Any help appreciated!

share|improve this question

1 Answer 1

up vote 2 down vote accepted

This is how you'd remove the .html extension using a .htaccess file

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
# Replace html with your file extension, eg: php, htm, asp

To add a trailing slash at the end of the URL (for example: http://www.example.com/about-us/ to go to http://www.example.com/about-us.html)

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.html 

# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
share|improve this answer
    
@anaglo does this have any effect on seo ? –  sam Nov 17 '12 at 23:17
2  
@sam yes if your website has already been indexed with file extensions changing your URL structure will most likely affect your rankings. You'll have to create 301 redirects from the old pages to the new pages. If it's a new website it does not matter which you use –  Anagio Nov 17 '12 at 23:34
    
great thanks! any idea how to set my default page? I have the line DirectoryIndex index.html site-down.php in there and my page is called index.html but it is showing a different one. –  clifgray Nov 18 '12 at 1:16
    
What page is it showing? –  Anagio Nov 18 '12 at 15:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.