mod_rewrite setting with .htaccess for Slim Framework on OpenShift - 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]

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.

from .html to no .html angular

so basically I've this htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
#RewriteRule ^(.*) /index.html [NC,L]
RewriteRule ^ index.html [L]
</IfModule>
but old website has all the .html url's like www.mysite.com/contact.html
thing is it's first page in a lot of google searches and i don't want to loose all that indexed pages, so i what i want is to get that and remove the .html
also, i've custom url's like www.mysite.com/product/whatever_my_name.html
same story, grab that and make it www.mysite.com/product/whatever_my_name
thanks in advance
RewriteCond %{REQUEST_URI} ^((?:/[^/]+)+).html$
RewriteRule ^ %1 [NS,L,R=301]
Testing only the client's request is important to avoid interference with serving any other html docs, e.g. your main index.html.

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

How does URL without extensions such as HTML work?

For example,
https://stackoverflow.com/questions/ask
ask does not have .html but takes me to the page I want. How does this all work? And where can I learn more about this?
It is made from the .htaccess file where you make rules for your website/server.
By having http://stackoverflow.com/questions/ask as the address the server will interpret it as http://stackoverflow.com/questions/ask.php or http://stackoverflow.com/questions/ask.html...
You can check this site
Add .htaccess file in your root folder of your domain with following code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.html [L]

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]