Zubo
Zubo

Reputation: 23

Altorouter path differences on localhost vs remote server

I am wondering how to remove "/" from link paths in .htaccess (I assume) when navigating a site on localhost (localhost/mysite) that was is on the root of a remote server (www.example.com). This routing is done with Altorouter and in order to get any functionality I added setBaePath("/myProject") which works. My problem is that any links in the site (e.g. "/home") have a slash that results in the browser going to "localhost/home" instead of "localhost/mysite/home". Do I need to make changes to the .htaccess file to parse out "/" from all the links within the site?

.htaccess file

Options -Indexes

RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]


<filesMatch "\.(html|htm|js|css|php)$">
  FileETag None
 <ifModule mod_headers.c>
   Header set Cache-Control "no-cache, must-revalidate"
 </ifModule>
</filesMatch>

index.php (The 2 lines I added to index.php have a "*" in front of them.)

require __DIR__ . '/../vendor/autoload.php';
* require __DIR__ . '/../vendor/altorouter/altorouter/Altorouter.php';



$router = new AltoRouter();
* $router->setBasePath('/mysite');

// MAIN PAGES
$router->map('GET', '/', function() {
    require __DIR__ . '/../views/hello.php';
});
$router->map('GET', '/home', function() {
    require __DIR__ . '/../views/home.php';
.
.
.

$match = $router->match();

// call closure or throw 404 status
if( is_array($match) && is_callable( $match['target'] ) ) {
    call_user_func_array( $match['target'], $match['params'] ); 
} else {
    // no route was matched
   header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}

Upvotes: 0

Views: 129

Answers (0)

Related Questions