.htaccess remove .html - html

I realize there is another post about how to remove .html but it is not working for me so I am trying to understand a little better how this process works.
I have fatcow for my hosting service. I downloaded the .htaccess from fatcow and it downloaded at a .htm file. I inserted this code via notepad.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)/$ $1.html
</IfModule>
I saved the file as .htaccess and uploaded it to my root folder on fatcow. It is now saved in my root folder as .htaccess.txt
What am I doing wrong here to where this is not working?
UPDATE:
I renamed the .htaccess.txt to .htaccess via FTP client. It shows up at .htaccess now but it is still not removing the .html from my urls.

It should be saved as .htaccess, not .htaccess.txt.
It might be named this way because you created the file on Windows. If this is the case, you have two options:
Upload, then rename
Once the file is uploaded to the server, you can most likely rename the file to have the correct name.
Rename, then upload
You can rename it by doing the following in the Command Prompt:
cd C:\Directory\With\File\In\It
rename .htaccess.txt .htaccess
Once that is done, it should be named .htaccess properly, and can be uploaded.

Related

Can anyone access protected (with .htaccess) json files in the host?

I have important config.json file, contains important data (like database username, password, etc...) and I'm protecting it using htaccess.
Can anyone access this file using any method (like hacking or anything like that)?
Full htaccess code:
<IfModule mod_rewrite.c>
DirectoryIndex index.php index.html
RewriteEngine On
# RewriteBase /
RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php [QSA,L]
Options -Indexes
# protect files
<FilesMatch "\.(sql|data|conf|dat|json|inf|info)$">
Order allow,deny
Deny from all
</FilesMatch>
</IfModule>
** Related Info: The server I'm using is apache with PHP code. Also my files is in a shared hosting company. **

Correct way to remove folder name from website URL

There are a couple of posts that cover the question of removing folder paths from URLs, but none of the answers explain how to link the page using html after adding the .htaccess code.
The folder structure looks like this:
root
.htaccess
index.html
folder
games.html
I am using the following code to remove the folder path "folder" from the URL.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder/$1 [L]
Would the correct way to "load" the page games.html from the index.html file be:
games
and wouldn't it be a conflictual issue if i have a games.html file in the root folder as well?
Using the method below includes the folder name in the URL. Is it possible to remove the folder name from the URL whilst still being able to link to the page using the entire path?
games
I would appreciate if my provided .htaccess code can be simplified or if there is a better way to write the code.
Assuming you have this rule in site root .htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ folder/$1 [L]
Let me answer each question as I understand.
Q1. What should be correct html code for having a link?
A1. You can have:
games
Q2. If games.html exists in root directory then which file will be shown?
A2. Apache will present games.html from root because of RewriteCond %{REQUEST_FILENAME} !-f condition which rewrites to folder/ only if file doesn't exist in request.
Q3. What should be the correct rule?
A3. It is better to have your rule as:
RewriteCond %{REQUEST_URI} !^/folder/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ folder/$1 [L]
This way you can avoid infinite looping if rewritten file or directory doesn't exist in folder/ directory.

htaccess , can't access homepage

I'm trying to set locally a project that run on the web on a NGIX server. This is the htaccess i have downloaded:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~sitename/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~sitename/index.php [L]
</IfModule>
I'm trying to run it locally on an Apache server(on mamp) . It have placed the project in a folder on the server root:
http://localhost/sitename/
But i get a blank page.
I can access a specific internal page (and only that one) if i remove the tilde
~
Even without the tilde, i can't access the homepage of the project.
So what i'm doing wrong?
How the tilde works in this context ?
EDIT
my mod_rewrite is loaded/enabled

I don't want .html in url of website

My html page is showing .html at the end of url I want to remove that. Can anyone help me out.
My url are like
mysitedoain.com/about.html
..../contact.html
You need to create a file called '.htaccess' in the root directory of your site containing the following code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
I hope this will work! after that you can access your pages without .html.
The answer here seems to be what you're looking for.
tl;dr: create a .htaccess file in your root directory with a rule to rewrite the url, removing the .hmtl
Create a file called '.htaccess' in your root directory and rewrite it with this.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
You need to create an .htaccess file. In order to do that, open Notepad on your computer. In Notepad, input the following:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html
In order to save the file, go to File > Save As. For the file name, call it “.htaccess” without the quotes. Change the Save As Type to “All Files.”
Once you have the file saved, upload it to your public_html folder on the server. The last thing you’ll have to do is remove .html from all of your file names.

Removing html file extensions from website urls

Im editing my .htaccess file in the root folder of my website server to get rid of all the .html extensions in the URL's (4 in total) and I save it and its not working. Obviously something I'm doing wrong...
This is what i have in .htaccess:
# Begin Muse Generated redirects
# End Muse Generated redirects
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Use this if you must use .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]