Comments (7)
Can you please give me some more details about your setup?
- How do you open the installation in your browser? Is this http://localhost/simplePHPRouter ?
- If this is the case: What happens if you connect your browser to http://localhost/simplePHPRouter ?
- Have you configured your basepath in index.php and in .htaccess? See this section: https://github.com/steampixel/simplePHPRouter/blob/master/README.md#use-a-different-basepath
You have to configure you basepath if you script lives in a subfolder like /simplePHPRouter
from simplephprouter.
Link: http://localhost/simplePHPRouter
Code from index.php "
`<?php
// Use this namespace
use Steampixel\Route;
// Include router class
include 'src/Steampixel/Route.php';
// var_dump($_GET);
// exit();
function navi() {
echo <<<EOD
Navigation:
- home
- index.php
- edit user 3
- foo 5 bar
- long route example
- contact form
- get+post example
- test.html
- PHP Info
- aTrailingSlashDoesNotMatter
- aTrailingSlashDoesNotMatter/
- theCaseDoesNotMatter
- thecasedoesnotmatter
- 404 Test
- 405 Test
// Add base route (startpage)
Route::add('/', function() {
navi();
echo 'Welcome :-)';
});
// Another base route example
Route::add('/index.php', function() {
navi();
echo 'You are not really on index.php ;-)';
});
// Simple test route that simulates static html file
// TODO: Fix this for some web servers
Route::add('/test.html', function() {
navi();
echo 'Hello from test.html';
});
// This route is for debugging only
// It simply prints out some php infos
// Do not use this route on production systems!
Route::add('/phpinfo', function() {
navi();
phpinfo();
});
// Post route example
Route::add('/contact-form', function() {
navi();
echo '
}, 'get');
// Post route example
Route::add('/contact-form', function() {
navi();
echo 'Hey! The form has been sent:
';
print_r($_POST);
}, 'post');
// Get and Post route example
Route::add('/get-post-sample', function() {
navi();
echo 'You can GET this page and also POST this form back to it';
echo '
if (isset($_POST['input'])) {
echo 'I also received a POST with this data:
';
print_r($_POST);
}
}, ['get','post']);
// Route with regexp parameter
// Be aware that (.) will match / (slash) too. For example: /user/foo/bar/edit
// Also users could inject SQL statements or other untrusted data if you use (.)
// You should better use a saver expression like /user/([0-9])/edit or /user/([A-Za-z])/edit
Route::add('/user/(.*)/edit', function($id) {
navi();
echo 'Edit user with id '.$id.'
';
});
// Accept only numbers as parameter. Other characters will result in a 404 error
Route::add('/foo/([0-9]*)/bar', function($var1) {
navi();
echo $var1.' is a great number!';
});
// Crazy route with parameters
Route::add('/(.)/(.)/(.)/(.)', function($var1,$var2,$var3,$var4) {
navi();
echo 'This is the first match: '.$var1.' / '.$var2.' / '.$var3.' / '.$var4.'
';
});
// Long route example
// By default this route gets never triggered because the route before matches too
Route::add('/foo/bar/foo/bar', function() {
echo 'This is the second match (This route should only work in multi match mode)
';
});
// Trailing slash example
Route::add('/aTrailingSlashDoesNotMatter', function() {
navi();
echo 'a trailing slash does not matter
';
});
// Case example
Route::add('/theCaseDoesNotMatter',function() {
navi();
echo 'the case does not matter
';
});
// 405 test
Route::add('/this-route-is-defined', function() {
navi();
echo 'You need to patch this route to see this content';
}, 'patch');
// Add a 404 not found route
Route::pathNotFound(function($path) {
// Do not forget to send a status header back to the client
// The router will not send any headers by default
// So you will have the full flexibility to handle this case
header('HTTP/1.0 404 Not Found');
navi();
echo 'Error 404 :-(
';
echo 'The requested path "'.$path.'" was not found!';
});
// Add a 405 method not allowed route
Route::methodNotAllowed(function($path, $method) {
// Do not forget to send a status header back to the client
// The router will not send any headers by default
// So you will have the full flexibility to handle this case
header('HTTP/1.0 405 Method Not Allowed');
navi();
echo 'Error 405 :-(
';
echo 'The requested path "'.$path.'" exists. But the request method "'.$method.'" is not allowed on this path!';
});
// Run the Router with the given Basepath
// If your script lives in the web root folder use a / or leave it empty
Route::run('/');
// If your script lives in a subfolder you can use the following example
// Do not forget to edit the basepath in .htaccess if you are on apache
// Route::run('/api/v1');
// Enable case sensitive mode, trailing slashes and multi match mode by setting the params to true
// Route::run('/', true, true, true);`
"
On click >> http://localhost/simplePHPRouter Show this :
Error 404 :-( The requested path "/simplePHPRouter" was not found!
from simplephprouter.
try changing your path to /simplePHPRouter/ since your executing the script there.
Route::run('/simplePHPRouter/');
or
Route::run('./');
from simplephprouter.
Idem.
"Error 404 :-(
The requested path "/simplePHPRouter" was not found!"
from simplephprouter.
Hi,
I think you have done something strange :-) (I hope so ;-) )
- Make sure you have a real folder called "C:\xampp\htdocs\simplePHPRouter" on your HDD
- Extract all the contents of the repo to that folder. That means you have files like "C:\xampp\htdocs\simplePHPRouter\index.php", "C:\xampp\htdocs\simplePHPRouter.htaccess", "C:\xampp\htdocs\simplePHPRouter\src\Steampixel\Route.php", etc...
- Make sure the index.php file is reachable by calling http://localhost/simplePHPRouter
- Double check this by calling http://localhost/simplePHPRouter/README.md This should deliver the readme file directly to you and not an error.
- Make sure using "Route::run('/simplePHPRouter');" in your C:\xampp\htdocs\simplePHPRouter\index.php file
- Make sure using "RewriteBase /simplePHPRouter/" in C:\xampp\htdocs\simplePHPRouter.htaccess instead of "RewriteBase /"
Can you confirm this? If you can confirm this there must be another strange kind of an error.
from simplephprouter.
Hi,
Now, worked on click on http://localhost/simplePHPRouter/
But when I click on http://localhost/simplePHPRouter/test.html redirect me to http://localhost/test.html .
In index.php from directory simplePHPRouter, I put :
Route::add('/test.html', function() {
navi();
echo 'Hello from test.html';
});
from simplephprouter.
Hey,
the router does no automatic redirection. I think you missed to alter the menu. In the index.php file there is a function to print a simple demo menu called navi(). But this menu only works if the router runs directly on the domain without subfolder. Read this section: https://github.com/steampixel/simplePHPRouter#use-a-different-basepath. Take a look at the HTML links inside the menu. They will point hard to /test.html and other locations relative to the domain. There is no automatic link generator that will replace the demo links with /simplePHPRouter/test.html . They will still point to the defined locations.
If you want you can define your basepath as a variable on top of your index.php. You can than use this variable inside the Route::run call and you can use this variable to automatic prepend your links with your basepath.
I will create a new issue to pick up this idea for the demo index.php
from simplephprouter.
Related Issues (20)
- proper way of a 404 error page display HOT 2
- Apache removes all $_REQUEST, $_POST, etc HOT 6
- haeder Problems HOT 11
- add Route by HOT 5
- everything redirects to 404 HOT 2
- multilanguage router HOT 4
- File protection from direct access HOT 8
- Override all Routes/Maintenance Mode HOT 2
- can you provide an additional example for the api example ? HOT 7
- all routes should return the full url of the page and its title HOT 4
- How to use Views with this Router? HOT 7
- Grouping/Sub-Route Request. HOT 2
- Example for named function with parameters HOT 1
- Further options in url HOT 1
- "Use return instead of echo": doesn't work when the function is called by pathNotFound() HOT 1
- Subdomain Support HOT 1
- excluding a directory from using the route? HOT 5
- Using query parameters HOT 3
- Redirect to another route HOT 1
- URI with symbols HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simplephprouter.