Htaccess removing .html - html

This is code from my .htaccess file
AddDefaultCharset UTF-8
Options -Indexes
# blocks direct access to the XML files - they hold all the data!
<Files ~ "\.xml$">
Order allow,deny
Deny from all
Satisfy All
</Files>
<Files sitemap.xml>
Order allow,deny
Allow from all
Satisfy All
</Files>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mywebsite.co.uk$ [NC]
RewriteRule ^(.*)$ http://mywebsite.co.uk/$1 [R=301,L]
# Usually it RewriteBase is just '/', but
# replace it with your subdirectory path
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /?([A-Za-z0-9_-]+).html$ index.php?id=$1 [QSA,L]
Most of it was previously generated not by me, and that's may be the problem i cannot understand it. I wanted to remove .html from mywebsite.co.uk/promotions.html.
I have tried adding, deleting lines and searched for answers for a long time and i still get nothing. Everything i get is sth like: mywebsite.co.uk/?id=promotions which is even worse. Actually i am newbie with htaccess and most of this code is more or less magic for me. I would be happy to get some help.

You need to do it like this
RewriteCond /%{REQUEST_FILENAME}.html -f
RewriteRule ^([a-zA-Z0-9_-\s]+)/$ /$1.html

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

Capital letters URL with cPanel?

my website have this link, but when I change hello to HELLO, page is not found
www.mywebsite.com/hello
I've searched a lot of question about capital letters URL. The answer is basically the same, which is setting the .htaccess and setting the RewriteMap httpd.conf. My website is using cPanel 62.0.15 and I don't think that I can access httpd.conf. I didn't found that file anywhere.
Is there any other way to get capital letters URL working? Or where can I find the httpd.conf file in cPanel?
My .htaccess
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteBase /
RewriteRule ^(.*)$ index.php?xparam=$1 [QSA,L]
</IfModule>
If you add NC as a RewriteRule then this makes the match case insensitive:
RewriteRule ^(.*)$ index.php?xparam=$1 [QSA,L]
Becomes ..
RewriteRule ^(.*)$ index.php?xparam=$1 [QSA,L,NC]
See https://httpd.apache.org/docs/current/rewrite/flags.html for more

HTML - Rename index.html for every folder

So I am fairly new to html and web development. I am currently playing around with a small website and wondered if it is possible to rename the 'index.html' file in every subfolder.
I have read a little about the htaccess file but could not find anything specific to my problem.
I want to be able to have something like www.example.com/test with test.html in the /test folder acting as the index.html and the same for www.example.com/apple with apple.html and so on, without having to have 100 index files in total as that seems pretty confusing.
Is this possible with htaccessand how if it is? If not is it possible at all?
You can use:
RewriteEngine on
# remove html (to avoid duplicate content)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R=301,L]
# rewrite html only if file exists
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^([^.]+)/?$ $1.html [L]
In your .htaccess you do like this
RewriteRule ^index.*$ index.php [NC]
So in other words you replace index.php with what you want to be changed and index with the name that users you want to see.You can also do this with arguments like
RewriteRule ^welcome.*$ index.php?page=welcome [NC]
Try this rule i am assuming files and folder's are present in manner as you have said.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)/$ $1/$1.html [L]

getting html5 boilerplate .htaccess file to work on dreamhost site

Completely new to Apache.
Trying to remove ".html" extension from urls by adding the following lines (found here):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
to this (including ^ those lines now):
<IfModule mod_rewrite.c>
RewriteEngine On
# Enable the `FollowSymLinks` option if it isn't already.
# Options +FollowSymlinks
# If your web host doesn't allow the `FollowSymlinks` option, you need to comment it out or remove it, and then uncomment the `Options +SymLinksIfOwnerMatch` line, but be aware of the performance impact.
# Options +SymLinksIfOwnerMatch
RewriteBase /
# RewriteOptions <options>
RewriteCond %{HTTPS} =on
RewriteRule ^ - [env=proto:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^ - [env=proto:http]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
</IfModule>
But the .html extensions remain in the visible urls.
I couldn't find any info on whether Dreamhost allows FollowSymLinks, but I tried it enabled, as well as SymLinksIfOwnerMatch, I also tried disabling RewriteBase / and even removing the mod rewrite if statement. I'm placing the file in my website's root directory, and tried placing it in the parent folder to that too with no results. Anybody have an idea what I'm doing wrong?
The full .htaccess is here.
Solved:
I still don't know why the above code didn't work, but I just used the code from Dreamhost's wiki instead:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\ HTTP/
RewriteRule ^(.*)index$ http://Your_Site_Url_Goes_Here.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://Your_Site_Url_Goes_Here.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+)\.html\ HTTP/
RewriteRule ^(.+)\.html$ http://Your_Site_Url_Goes_Here.com/$1 [L,R=301]
RewriteRule ^([a-z]+)$ /$1.html [L]
</IfModule>
Be mindful that the above code may cause new problems, as it is causing one of my pages to return a 403 Forbidden error, but I think that's a whole other problem irrelevant to my original question so I consider this a solve and will fix the above code when I find a solution elsewhere.
Symlinks seem to have been irrelevant.
.htaccess file goes in >mySite.com directory, rather than the directory that contains this directory
DreamHost wiki has a guide on how to use Apache redirects and rewrites. The guide mentions FollowSimylinks
You should also check the Apache error logs to see what fails (and edit your question to be more specific about the result you see in the browser).

mod_rewrite - neewd to make an exception for addresses that contain a certain word

HI, I have a mod_rewrite in my .htaccess file that is reformatting address. I already have one exception that will keep .cfg files free from the rewrite, I'm trying to do that same with .html files that contain the word "client" but have had no luck trying a number of different approaches. I'm out of my depths with .htaccess stuff unfortunately.
Here is the file currently:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule \.cfg$ - [L]
RewriteRule client - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php
</IfModule>
Any help would be greatly appreciated!
Change the client line to:
RewriteRule client(.*?)\.html - [L,NC]