.htaccess file does not overwrite html and instead shows markup on page - html

I'm building a personal website, and I want my url links to look like domainname.com/example as opposed to domainname.com/example.html
I'm using fastcomet for my webhosting service. Under my public_html folder I have a .htaccess file. Here is the code for my .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
</IfModule>
My .htaccess file and all my html, css, js files are under home/username/public_html/ and I've removed the .html extensions from all my html files. After I applied these changes, I tried to get http://domainname.com/example and I saw the html markup as opposed to the rendered html such as:
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<all my code .... />
</html>
Any suggestions on what I should do? I am placing the .htaccess file in the wrong directory? I also tried with and without the Ifmodule tags on the .htaccess file.
Thanks!

Yes, indeed, you should keep the file extension .html so you can have your files properly handled and your .htaccess to work as intended. It seems that in the meantime, you have actually posted the ticket to our Tech Support Team. Though there has been a slight misunderstanding regarding your request, a senior member of our team successfully excluded the processing of HTML and HTM files from the NginX service and they are now passed directly to Apache for your domain. As a result, all of your url links now look like domainname.com/example as opposed to domainname.com/example.html. Should you have any further requests, do not hesitate to contact us back!

I've removed the .html extensions from all my html files
This is why you see page code.
Rename the files back and use the following rewrite rule:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
</IfModule>

FastComet Team here! Part of our shared hosting environment is utilizing NginX as a reverse proxy to the Apache web service. This means that static content, such as HTML files, is processed directly by NginX and not by Apache. This is why any rules that you apply to the .htaccess file of your website are not making any actual changes. The requests to HTML files will be processed directly by NginX and they will not be passed to Apache so the .htaccess rules will be ignored.
There is an easy way of resolving that. We can exclude the processing of HTML and HTM files for your domain or even your entire hosting account. This way, those requests will be processed by the Apache web server, instead of NginX. In this case, the .htaccess rules that you apply will be taken into consideration by the system and they will work without any issues. To achieve that, simply submit a ticket to our Technical Support team and we would be happy to assist.

Related

how to remove the url extension

I am developing a website for myself, pure and without server language.
The urls are as they are called in the a tag, for example: blog / index.html.
Is there anything I can use to change that? I don't want to have to use framework. I would like to know if there is any tool that does this.
What I want to change is the ending. I don't want the extension to appear, just the route
try create .htaccess file on your root folder then paste this
#remove html file extension-e.g. https://example.com/file.html will become https://example.com/file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
you can read more about this here https://www.plothost.com/kb/how-to-remove-php-html-extensions-with-htaccess/
EDIT
Since you are using Vercel.com, as per their documentation there's a file config named vercel.json you can add this
{
"cleanUrls": true
}
the docs said,
When set to true, all HTML files and Serverless Functions will have their extension removed. When visiting a path that ends with the extension, a 308 response will redirect the client to the extensionless path.
for more information pls read their docs here https://vercel.com/docs/configuration#project/clean-urls

How can i remove .html from static html website pages

I have a static website with static files (pages), I would like the URLs of the pages not to contain .html at the end, for example:
"www.mywebsite.com/page.html" to become "www.mywebsite.com/page"
of course I can't just redirect the page, since the file "www.mywebsite.com/page" isn't known
Thanks in davance
I would recommend you use URL rewriting for your server's config file.
For example if you are using an apache server, you could use
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html[NC,L]
in your .htaccess file (which is the config file for your apache server.

Broken images on CodeIgniter website after uploading to server

I uploaded my CodeIgniter website to the server, but after uploading the website layout is not working properly. Some images work, but other images are not showing.
My .htaccess file:
RewriteEngine On
RewriteBase /beta
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|system)
RewriteRule ^(.*)$ /beta/index.php?/$1 [L]
The base URL in config/config.php:
$config['base_url'] = 'https://www.lalcoresidency.com/beta/';
Here is my website link: https://www.lalcoresidency.com/beta/
There are several things to check that will help you trouble shoot.
The very first thing to do is to confirm that the image folders and files are actually on the server.
Try to figure out what the missing images have in common. Are they all in the same folder? If so, are permissions for that folder and its files set appropriately?
The owner of the folder(s)/file(s) will also need to be set appropriately. This will depend on the server. Many Apache based servers have the owner set to www-data.
Are any of the images loaded through css? For example, background-image: url("images/ui-icons_444444_256x240.png")? If so, confirm that the css file(s) are actually loading. Your browser's development tools will be invaluable for this. (Firefox uses Firebug and Chrome uses Web Developer)
I don't see any obvious problems with your .htaccess file.

How do I redirect "website/page" to "website/page.html" when people type it in browser (pretty-url)

I recently started using a static site with godaddy.com without a cms. It's a basic website I uploaded and is only html/js/css.
When people type "website.com/page" they get 404 not found.
When they type "website.com/page.html" they get the correct page.
How can I fix my site so users can simply type "website/page" and not be forced to type "website/page.html" without using php?
SOLUTION
After researching the information about .htaccess files provided by #Gijsberts (thank you), I did the following:
Created a .htaccess file on server.
Added the following code:
# Remove the .html extension from html files
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]
Most CMS systems have a .htaccess file what handles the redirect and the 404 errors. In CMS system they are most called "Pretty-urls". Read the links below to set up those pretty urls yourself with a static web page without a cms.
https://mediatemple.net/community/products/grid/204643080/how-do-i-redirect-my-site-using-a-htaccess-file
http://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049
You normally can do this with your Webserver config. In Apache you have this enabled automatically. In nginx you should have a look at this tutorial.
If you are using caddy you have to config your caddyfile like
ext .html .htm .php
if you are using microsoft iis have a look at microsofts tutorial.
Let me know if you are using something else or need more help.
EDIT
If you are using a webspace you may are not able to change the config of the webserver. you now can use .htaccess. create a .htaccess file and write down something like
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

How to make URLs in a website appear solely as folders

I am trying to design a folder structure for a website project I am working on. A lot of sites these days seem to have the following link structure:
www.example.com/news/news-item-one/
www.example.com/about-us/
Can I make my site work like this without making a new folder for each page I have and putting an index.php file in it?
i.e www.example.com/news/new-item-one.php reads www.example.com/news/news-item-one/
You can use a web application framework like CodeIgniter or CakePHP to do URI routing for you:
http://codeigniter.com/
http://cakephp.org/
This is done with an .htaccess file which either of those frameworks can provide in example documents and they have extensive documentation about URI routing. For example on CI:
http://codeigniter.com/user_guide/general/urls.html
Yes, but it depends what server you are running.
If Apache, one of the most common ways is to create an .htaccess file and use rewrite rules to declare the different routes your website uses.
Below is a very simple example, although not necessarily the best way. There are things you can do to make it more flexible, but I believe it's out of scope of this question. For what it's worth, I prefer a catch-all route that passes route handling to my framework.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^news/(.*)$ news.php?item=$1 [NC,L,QSA]
RewriteRule ^about-us/$ about-us.php [NC,L,QSA]
</IfModule>
You want to use htaccess.
Create a file in your root directory called .htaccess with the following
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)$ $1.php [NC]
You don't need to use a framework (although it may be a good idea). You can simply setup your .htacess correctly:
http://www.evolt.org/Making_clean_URLs_with_Apache_and_PHP
The following mod_rewrite code (to put in your Apache configuration) will allow you to hide the .php extension of any page you have on your site.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule ^(.*)$ $1.php [L]
It checks to make sure something isn't a file or directory itself, then that adding .php after it's name actually is a file, and it serves that instead.
So if you have a /page.php on your site, going to /page will be the same as going to /page.php.