How to remove html extension from url without htaccess

This is my site. http://matiny.tk/Antihero.html As you can see, the .html extension is just sitting at the end. .htaccess does not work for me. It causes the CSS to go missing, or the site to have a 500 internal error.

I'm using cPanel.

Here are the codes that aren't working.

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

This next one is only slightly different.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html

I got this one from someone on Youtube...

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1 .html [L,QSA]

How to remove html extension from url without htaccess

Dharman

27.9k21 gold badges75 silver badges127 bronze badges

asked May 22, 2014 at 20:57

6

There is one ugly work-around:

rename your file to index.php and put it inside a folder called Antihero.

But better is to use .htaccess. You say you cannot use it. Show us your .htaccess and we'll help you use it!

edit Try this in your .htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [L,QSA]

answered May 22, 2014 at 21:06

nl-xnl-x

11.6k7 gold badges31 silver badges60 bronze badges

6

What you're wanting are what's called pretty URLs.

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^Antihero$ ./Antihero.html

This way you can share your link as http://matiny.tk/Antihero and you're apache will preserve that url while underneath it's actually serving Antihero.html.

See here for some more information: http://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049

EDITED: Your last example works fine for me in my htaccess files. [Links to examples have been removed (no longer using .htaccess on the server)]. If it's still not working, could you verify that your htaccess support is enabled in apache?

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html

answered May 22, 2014 at 21:07

How to remove html extension from url without htaccess

View Discussion

Improve Article

Save Article

  • Read
  • Discuss
  • View Discussion

    Improve Article

    Save Article

    All the pages on the website have a structure which is given by HTML. HTML provides the structure to content, text, tables, headings, and lists on the webpage that makes the page easy to read. While saving an HTML document it has an extension as .html. Therefore, the URL of the website have a .html extension. The .html extension can be easily removed by editing the .htaccess file.

    .htaccess file: The .htaccess file is created with a Text Editor like Notepad. It is a simple ASCII file that lets the server know what configuration changes are to be made on a per-directory basis.

    Note: The .htaccess is the full name of the file. It is not file.htaccess, it is simply .htaccess.

    Removing .html Extension: To remove the .html extension from a URL. For example: 
    From  

    example.com/content.html

    To 

    example.com/content

    You have to follow these steps: 

    • Log in to cPanel account.
    • In the Files section, click on the File Managericon.
    • Click on the Settings Button in the top right corner.
    • If you want to make changes in the Primary Domain then Click on the radio button next to the Web Root. If changes are to be made on Other Domains, then Click the dropdown menu and find the domain in which changes are to be made.
    • Remember to check the checkbox next to Show Hidden Files. Now click the Save Button to return to the File Manager window.
    • Now you are in the Root Folder of the domain which you have selected to make changes. Search for the .htaccess file and right-click on it. Click on the Edit option in the menu. You can now add code to the .htaccess file.
    • Add the following code inside the .htaccess file

    HTML

    • Click on the Save Changes Button and then on Close Button.

    You can now link any page inside the HTML document without needing to add the extension of the page as no extension will be visible now in the URL of the website.

    Example:  

    <a href="http://example.com/image" title="image">image</a>

    The search engine may index these pages as duplicate content, to overcome this add a <canonical> meta tag in the HTML file. 

    Example:  

    <link rel="canonical" href="https://example.com/blog/first-blog" />

    How do I remove .html from URL?

    html extension can be easily removed by editing the . htaccess file.

    How do I remove a PHP from a URL?

    How to Remove ..
    Open htaccess file. Open terminal and run the following command to open . htaccess file. ... .
    Remove . php extension from URL. ... .
    Restart Apache web server. Restart Apache server with following command $ sudo systemctl restart httpd..