Can a localhost directly lead to an html file? - html

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

Related

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 .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.

How to have a pure HTML (from index.html) directory in a cakePhP site?

I have a cakePhP site all set up. It has its "webroot" directory and some sub-directories that each have their own "app" directory. They all work fine. Now I want to set up a sub-directory that runs from just an "index.html" file, no "app" directory or cakePhP directory structure with a Controller file etc. It would be a pure HTML sub-directory.
If I just add a subdirectory containing just an "index.html" file (no ".htaccess" file in it) I get a cakePhP error saying the controller file for that directory is missing.
The ".htaccess" file of the overall "webroot" directory looks like this. I cannot change that ".htaccess" file because the other sub-directories depend on those rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Does anyone know what I need to do e.g. set up a local .htaccess file in my sub-directory to make my sub-directory work with just HTML?
Inside webroot/html folder create some html files, index.html, ...
test http://somesite.com/html/index.html
A possible solution is to hard code your sub-directory as the the first RewriteRule. Let's say your regular HTML sub directory is called "html".
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule /html$ app/webroot/html [L]
RewriteRule /html/(.*) app/webroot/html/$1 [L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
This way it will check if you are trying to access the sub directory before the rules for Cake are checked. I haven't tested this, but give it a try.

Clean/Short URLs using .htaccess is not working as it should

I've been following some YouTube videos to try and get this working but it doesn't seem to want to. This is how my .htaccess file is looking:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule RewriteRule ^(.*)$ index.php/$l
I am completely new to .htaccess, I'm not completely sure how it works but my common sense tells me to just create a file, call it .htaccess and place it in the same folder as my index.php, right?
So when I go to, say index.php/foo/bar or even just /foo/bar/ I get a 404 error.
What are the possible problems? It's a Windows 2008 Server with PHP 5.3.10 installed.
As beginning your last line should be
RewriteRule ^(.*)$ index.php/$l
And it should work as you expect it... pass all requests but ones for existing files/folders into index.php
The .htaccess can be in any folder which is hit by the request URL... the only difference is the base of the URL which is relative to the folder where is the .htaccess located
Example:
/folder1
.htaccess
index.php
/folder2
.htaccess
index.php
If you access /test.php none if your .htaccess files will be processed (it's not related to the request URI.
If you access /folder1/test.php the corresponding .htaccess in folder1 will be used and the $1 in your RewriteRule will show test.php, the /folder1/ will be stripped from the URI.
If you access /folder1/folder2/test.php it's similar... apache will use .htaccess from folder2... the one from folder1 will be ignored (a bit counderintuitive)