getting html5 boilerplate .htaccess file to work on dreamhost site - html

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

Related

Folder name clashing with html page (using htaccess)

I have a static html website and I'm using .htaccess to clean up the url by removing the .html from the address.
The issue is when I visit "example.com/path" it clashes with the folder "path" but when I choose to manually enter example.com/path.html I will get the page loading just fine.
The URLs inside the "path" folder are working fine as well with "example.com/path/page1" both with and without .html file extension.
My only alternative just now is to change the folder name from the file name as subtle as possible until I find a solution.
I've had a look at related questions being asked as well as a bit of research on conditions to put into my .htaccess file but having no luck.
Appreciate any help.
EDIT ***
htaccess file ..
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.co.uk/$1 [R,L]
RewriteCond %{HTTP_HOST} !^www.example.co.uk$ [NC]
RewriteRule ^(.*)$ https://www.example.co.uk$1 [L,R=301]
Just returning a 403.
Kindly try below code
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*?)/?$ $1.html [L]
Note : Don't forget to replace RewriteBase. As of now i have added / bca my project is in root folder. You can simply add folder name like below
RewriteBase /yourfoldername/
Hope it will work for you.

mod_rewrite setting with .htaccess for Slim Framework on OpenShift

I am trying to setup Slim Framework on OpenShift.
According to this link, I have to have an .htaccess file like below in the same directory of the index.php:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
However, things seems to work a bit different on OpenShift, I ended up with the following .htaccess for OpenShift by referring to this link:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
It sure looks fine for me, but when I try to access the end point, PHP just returned me a 404. The default welcome index.php generated by OpenShift works fine though.
Appreciate if anyone can point me out where my mistake was. Thank you.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

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

does mod_rewrite on file extensions interfere with verification files?

I'm currently using mod_rewrite to remove the .HTML extension from files, as well as redirect to their friendly versions.
I use the pinterest.html and google.html files for verifying my Pinterest page and Google Apps account.
For mod_rewrite, I am using this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
My question is about the logic and function of it in relation to the verification files. The purpose as I understand is to serve 'x' file with 'y' URL.
So even though I am serving example.com/pinterest.html as example.com/pinterest due to the redirection and .HTML removal, there shouldn't be any interference since the file is still readable as always, correct?
Don't rewrite the two special files. Add a negative assertion to the cond regexp:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(?!pinterest\.html|google\.html).*\.html\ HTTP/
PS. why not just match %{REQUEST_URI} ?
RewriteCond %{REQUEST_URI} !(pinterest|google)\.html$
RewriteCond %{REQUEST_URI} \.html$
I've rewritten this in simple regexp. What this says is don't match the two special files but so match any other request for a .html file.

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]