Skip to content

Commit d01b8d0

Browse files
committed
fix htaccess and routes
1 parent 6ff3f83 commit d01b8d0

17 files changed

+19
-27
lines changed

.env.example

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CLOUDANT_HOST=""
2+
CLOUDANT_USERNAME=""
3+
CLOUDANT_PASSWORD=""

.htaccess

100755100644
+6-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
RewriteEngine On
2-
3-
# Some hosts may require you to use the `RewriteBase` directive.
4-
# If you need to use the `RewriteBase` directive, it should be the
5-
# absolute physical path to the directory that contains this htaccess file.
6-
#
7-
# RewriteBase /
1+
RewriteEngine on
82

3+
RewriteCond %{REQUEST_FILENAME} !-d
94
RewriteCond %{REQUEST_FILENAME} !-f
10-
RewriteRule ^ index.php [QSA,L]
5+
RewriteRule ^/?(api.*)$ index.php [L]
6+
7+
RewriteCond $1 !^(index\.php|public)
8+
RewriteRule ^(.*)$ index.php/$1 [L]
File renamed without changes.

public/index.php renamed to index.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@
1919
* This PHP file uses the Slim Framework to construct a REST API.
2020
* See Cloudant.php for the database functionality
2121
*/
22-
require '../vendor/autoload.php';
22+
require 'vendor/autoload.php';
2323
require_once('./Cloudant.php');
2424
$app = new \Slim\Slim();
25-
$dotenv = new Dotenv\Dotenv(__DIR__ . '/../');
25+
$dotenv = new Dotenv\Dotenv(__DIR__);
2626
$dotenv->load();
2727

28+
$app->get('/', function () {
29+
global $app;
30+
$app->render('index.html');
31+
});
32+
2833
$app->get('/api/visitors', function () {
2934
global $app;
3035
$app->contentType('application/json');

public/config.json

-14
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

public/index.html renamed to templates/index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<!-- Bootstrap -->
1111
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
12-
<link href="styles.css" rel="stylesheet">
12+
<link href="public/styles.css" rel="stylesheet">
1313
</head>
1414

1515
<body>
@@ -36,7 +36,7 @@ <h1>Welcome.</h1>
3636
//POST request to API to create a new visitor entry in the database
3737
$.ajax({
3838
method: "POST",
39-
url: "index.php/api/visitors",
39+
url: "./api/visitors",
4040
contentType: "application/json",
4141
data: JSON.stringify({name: name })
4242
})
@@ -50,7 +50,7 @@ <h1>Welcome.</h1>
5050

5151
//Retreive all the visitors from the database
5252
function getNames(){
53-
$.get("index.php/api/visitors")
53+
$.get("./api/visitors")
5454
.done(function(data) {
5555
if(data.length > 0) {
5656
$('#databaseNames').html("Database contents: " + JSON.stringify(data));

0 commit comments

Comments
 (0)