How to change example.com/blog.html to example.com/blog - html

www.tinynerdgames.com/blog.html
I want this page's URL to not end with /blog.html rather with /blog. So the wished end result would be: www.tinynerdgames.com/blog
What do I have to do?
Any answer is highly appreciated, thank you.

You can use the .htaccess file to truncate your file URL's.
Navigate to your File Manager in cPanel and locate the .htaccess file. Note: you must enable hidden files to view this file.
Click on Settings at the top right corner
Select Show hidden files (dotfiles)
Save new settings
Inside the htaccess file, paste this code;
#remove html file extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
Now change your link from to https://tinynerdgames.com/blog.html to https://tinynerdgames.com/blog and this should work perfectly.

Using FTP, you would log in to your website, create a directory named blog, move the blog.html file into the new directory, and rename blog.html to index.html.

Related

Can a localhost directly lead to an html file?

total newbie to HTML here. I set up my localhost with an html file but i have to acess it with localhost:8080/filename.html. is there a way to access it directly with localhost:8080?
Edit .htaccess file
Paste the following code at the beginning of the file changing the "filename.html" line with the page that you want to be served as your website's home page.
DirectoryIndex first.html
You can also set more than one index files as your website's homepage.
DirectoryIndex home.html index.html index.php
Depending on your operating envionment you should be able to accomplish this with an htaccess file. In your root directory create a file named .htaccess
Add this code:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
DirectoryIndex filename.html

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

Pointing webserver to load .html page and not subdirectory index

So I have been searching for a few hours now and have not found the answer to my problem.
So I have a website that I was wanting to take the page extension off e.g. .html / .php etc.. and I had found that I could include the below code in the .htaccess file.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
I have now added that code and it works great for removing .html from my pages. However now I have come into a new problem. I have a page and directory both named 'guides' on the root of my public_html folder. Now when I enter the url 'www.mydomain.com/guides' the index of the guides directory is showing rather than the guides.html page that I am wanting to display.
I am wondering what would be the best way to get around this and make my server look for the webpage first rather than display the guides directory index.
I have been looking at RewriteRule's but it seems to be all wordpress content and does not work with my non wordpress website.
Any help would be appreciated, thanks.
The best solution is to change the name of the directory or the file to something different. RewriteRule can not rewrite a directory request to file as the directory request is first handled by mod-dir (directory module) .
If you do not want to change the name, then you can turn off DirectorySlash on your server using the following line in htaccess :
DirectorySlash off
https://httpd.apache.org/docs/2.4/mod/mod_dir.html#directoryslash

How to set .htaccess so link in side html file will read from a base directory

Right now, I have put my html files under public/views folder,
libraries under public/libs, and customized files in public/src
I am using the DictoryIndex to set the default home page. Like DirectoryIndex public/views/index.html
but inside the index.html file, I have to use to open the file under the same directory as the index.html, otherwise it could not find the file. And then the URL will look ugly, like site.com/public/views/product.html.
Can I ask, how could I set the .htaccess file to get rid of the public/views in the URL address?
One more question, when i write the code to import the libraries in index.html, it seems like it will read from the base folder (like where I put the .htaccess file). But in the other html files, they will read from their own directory, like the html file in public/view will start to read from folder views. Is there anyway to solve this problem?
Thank you
Do you need to access your libs and custom files through HTTP too? If not, just set your document root to public/views
Otherwise, you could rewrite *.html to public/views using something like
Options +FollowSymLinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule (.+\.html)$ /public/views/$1 [L]
Anyway, using a fullpath instead of just a filename in the DirectoryIndex directive is not a good idea, for obvious reasons.
It also solves your second issue. For now, public/views/index.html is considered as / so anything relative to this file is relative to /, not the views folder. On the other hand, any other file is still considered as "itself", therefore includes are relative to the views folder.

How can I remove the .html from the end of URL pages

I want to remove the .html extensions from the end of the file names. As seen on the website: tekmillion.com
Any help will be appreciated, thanks.
Use this to remove extensions in your .htaccess.
An .htaccess file is a simple ASCII file that you create with a text
editor like Notepad or TextMate. It provides a way to make
configuration changes on a per-directory basis.
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /html/(.*).html\ HTTP/
RewriteRule .* http://localhost/html/%1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /html/(.*)\ HTTP/
RewriteRule .* %1.html [L]
Checkout this reference to learn more about this.
there is a way but it is not really good. You need to change the extension of your files from .html to .php and than you need to upload them to online hosting or you need XAMPP server.
Note: If you try to run files with .php extension the browser won't load them except if you have XAMPP server.
change the name of the files to index.html and put them in separate folders
http://tekmillion.com/videos.html
should become
http://tekmillion.com/videos/index.html
and you can acees it using the link
http://tekmillion.com/videos/
and you will not see the .html