Remove end part

Hi DarkCorpse,

You’re asking 2 things at a time:

  1. How to change from/to having file extension suffix
  2. How come the CSS is not referencing properly in your HTML page and breaks styles.

For #2, the CSS referencing only works when the URL rewrite settings is correct and the path points to the correct file, with exceptions set correctly in your .htaccess file. Simply rewriting everything to have no suffix would simply means assuming all files with .html extensions and something like css/style.html called from css/style definately doesn’t sounds like it’s gonna work.

Having the above in mind, for #1, you need to change the .htaccess file so that it only attempts to re-write when the file called does not exist.

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

Notice there’s the RewriteCondition for checking if the file is html before removing.

In the above code, the first line checks that the request is a URL and not a directory. The second line redirect matching URLs with .html extension to those without file extension. The last line redirects matching requests to URLs without html file extension.

In this case you can change HTML to call the CSS using something like css/style.css, keep the css extension so it calls to the existing file, and does not attempt any rewriting.

Cheers!

8 Likes