Skip to content

Commit 95b3f37

Browse files
committed
htaccess and routing in subdir fixes
1 parent 12cfc7c commit 95b3f37

File tree

6 files changed

+10
-12
lines changed

6 files changed

+10
-12
lines changed

bootstrap.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
$modules->loadRoutes($router);
7272

7373
// Cache the routes data
74-
$item = $cache->getItem('req_'.$requestURI);
74+
$item = $cache->getItem('routes');
7575
$routesData = $item->get();
7676
if ($item->isMiss()) {
7777
$item->lock();
@@ -86,7 +86,6 @@
8686
// Create Route Dispatcher object
8787
$dispatcher = new Phroute\Phroute\Dispatcher($routesData, $resolver);
8888

89-
9089
/**
9190
* Load Middlewares
9291
*/
@@ -95,10 +94,10 @@
9594
$relay = new Relay\RelayBuilder();
9695

9796
$relaydispatcher = $relay->newInstance([
97+
Middleware::basePath(BASE_PATH),
98+
Middleware::trailingSlash(),
9899
Middleware::responseTime(),
99100
new Plugins\Middlewares\LanguageDetect($language),
100101
new Plugins\Middlewares\Phroute($dispatcher)
101102
]);
102103
$response = $relaydispatcher($request, $response);
103-
$emitter = new \Zend\Diactoros\Response\SapiEmitter;
104-
$emitter->emit($response);

config/system.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/* BASE SETTINGS */
55
//define('BASE_URL',"http://".$_SERVER['HTTP_HOST']."/cms");
6-
define('BASE_PATH',""); // leave empty if not in subdir
6+
define('BASE_PATH',"/phreak"); // leave empty if not in subdir or "/phreak" for example subdir
77
define('BASE_URL',"http://localhost:8080".BASE_PATH);
88
define('ROOT_DIR', dirname(__DIR__));
99

plugins/middlewares/LanguageDetect.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
4545
$language = $first;
4646
//remove the language in the path
4747
$request = $request->withUri($uri->withPath('/'.array_shift($dirs)));
48-
$_SESSION['requestURI']=$request->getUri()->getPath();
4948
$this->language->current = $language;
5049
}
5150
return $next($request, $response);

plugins/middlewares/Phroute.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ public function __construct(Dispatcher $router)
3333
* @return ResponseInterface
3434
*/
3535
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) {
36-
// Create the Response Emitter
37-
$emitter = new \Zend\Diactoros\Response\SapiEmitter;
38-
3936
// Application is loaded. Execute Route Dispatcher
4037
// WITH PSR7 REQUEST/RESPONSE HANDLERS
4138
try {
39+
$_SESSION['requestURI']=$request->getUri()->getPath();
4240
ob_start();
4341
$this->router->dispatch($request->getMethod(), $request->getUri()->getPath());
4442
$bufferedBody = ob_get_clean();

public/.htaccess

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
RewriteEngine On
77

88
# Redirect Trailing Slashes If Not A Folder...
9-
RewriteCond %{REQUEST_FILENAME} !-d
10-
RewriteRule ^(.*)/$ /$1 [L,R=301]
9+
# RewriteCond %{REQUEST_FILENAME} !-d
10+
# RewriteRule ^(.*)/$ /$1 [L,R=301]
1111

1212
# Handle Front Controller...
1313
RewriteCond %{REQUEST_FILENAME} !-d

public/index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212
*/
1313
require_once __DIR__.'/../bootstrap.php';
1414

15-
15+
// Emit the response
16+
$emitter = new \Zend\Diactoros\Response\SapiEmitter;
17+
$emitter->emit($response);

0 commit comments

Comments
 (0)