Pointing webserver to load .html page and not subdirectory index - html

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

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

Deployed laravel app, only homepage working

I have recently finished a website for a customer, the site works great locally. Currently only the homepage is working. However all links return a 500 server error.
This is 1and1, and I haven't heard many good things about it.
Currently I have the laravel folders for my app within a folder called webapp.
the domain name points to webapp/public.
I have also added the following line to my htaccess to get it to work
RewriteRule ^ /home.php [L]
which works for the homepage. I don't know much about the htaccess file, so I've messed around with a few other options such as
RewriteRule ^ /folios.php [L]
as well which is one of the links in my site, however this doesn't work.
My routes currently work like this
Route::get('/folios', 'AlbumsController#index');
However they return 500 server error
Change the line in the ".htaccess" file in the root folder from RewriteRule ^ index.php [L] to
RewriteRule ^ /index.php [L]
My suspicion is that you need to update the paths contained within public/index.php
Check out this article for instructions: https://medium.com/#Bohr/deploy-laravel-application-on-shared-hosting-godaddy-953758dc57ac
Did you run composer install on the server or copy out the vendor directory? You may also want to check that your htaccess file in the public directory contains the directives that are required (https://github.com/laravel/laravel/blob/master/public/.htaccess).
I did not realize that the server generated a new .htaccess file within the /webapp/ folder where I pointed the domain; I was editing the wrong .htaccess file

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

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.

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