Comments (8)
For Apache your example works fine for me. Here is a tree of all included files. In my webroot I have created a "test" folder. Inside this I have created a "api" folder. Both folders and also the root folder have a .htaccess file and an index.php file. In this example I use the router three times in different dirs:
.
├── composer.json
├── docker
│ ├── image-php-7.2
│ │ └── Dockerfile
│ └── image-php-7.4.1
│ └── Dockerfile
├── docker-bash.sh
├── docker-build.sh
├── docker-rm.sh
├── docker-run.sh
├── include-example.php
├── index.php
├── LICENSE
├── README.md
├── release.sh
├── src
│ └── Steampixel
│ └── Route.php
├── test
│ ├── api
│ │ ├── composer.json
│ │ ├── composer.lock
│ │ ├── index.php
│ │ └── vendor
│ │ ├── autoload.php
│ │ ├── bin
│ │ ├── composer
│ │ │ ├── autoload_classmap.php
│ │ │ ├── autoload_namespaces.php
│ │ │ ├── autoload_psr4.php
│ │ │ ├── autoload_real.php
│ │ │ ├── autoload_static.php
│ │ │ ├── ClassLoader.php
│ │ │ ├── installed.json
│ │ │ ├── installed.php
│ │ │ ├── InstalledVersions.php
│ │ │ └── LICENSE
│ │ └── steampixel
│ │ └── simple-php-router
│ │ ├── composer.json
│ │ ├── docker
│ │ │ ├── image-php-7.2
│ │ │ │ └── Dockerfile
│ │ │ └── image-php-7.4.1
│ │ │ └── Dockerfile
│ │ ├── include-example.php
│ │ ├── index.php
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── src
│ │ │ └── Steampixel
│ │ │ └── Route.php
│ │ └── web.config
│ ├── composer.json
│ ├── composer.lock
│ ├── index.php
│ └── vendor
│ ├── autoload.php
│ ├── bin
│ ├── composer
│ │ ├── autoload_classmap.php
│ │ ├── autoload_namespaces.php
│ │ ├── autoload_psr4.php
│ │ ├── autoload_real.php
│ │ ├── autoload_static.php
│ │ ├── ClassLoader.php
│ │ ├── installed.json
│ │ ├── installed.php
│ │ ├── InstalledVersions.php
│ │ └── LICENSE
│ └── steampixel
│ └── simple-php-router
│ ├── composer.json
│ ├── docker
│ │ ├── image-php-7.2
│ │ │ └── Dockerfile
│ │ └── image-php-7.4.1
│ │ └── Dockerfile
│ ├── include-example.php
│ ├── index.php
│ ├── LICENSE
│ ├── README.md
│ ├── src
│ │ └── Steampixel
│ │ └── Route.php
│ └── web.config
└── web.config
27 directories, 60 files
Here are some examples of the different rewrite bases inside the htaccess files:
RewriteBase /
RewriteBase /test/
RewriteBase /test/api/
The basepath inside each index.php will change in a similar way:
define('BASEPATH','/');
define('BASEPATH','/test/');
define('BASEPATH','/test/api/');
Everything works as expected in my Apache example. Hops that helps for now.
from simplephprouter.
Perfect! Thank you. I will use this maybe as a basis when creating the nginx docker example.
from simplephprouter.
Hi @matteovisotto,
unfortunately I am not very familiar with Nginx server. So I don't know out of the box what the correct configuration is. Can you please share your configuration?
from simplephprouter.
That's my configuration. At the moment is the default site and the routing system is under test path:
#server configuration before this part (listen 80 and server name)
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
location /test/ {
if (!-e $request_filename){
rewrite ^(.*)$ /test/index.php;
}
}
location /test/api/{
if (!-e $request_filename){
rewrite ^(.*)$ /test/api/index.php;
}
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
I've noticed that adding location /test/api/ or deleting it the result is the same, a white page (not 404 from the main index) that could be a php script error but the code is the same of the main page (just for a test) and I have changed the include Route class path.
EDIT: no problem if you have a solution for Apache htaccess, I translate it :)
from simplephprouter.
Hi @matteovisotto
I will now create a nginx docker demo. So I can test your case. Unfortunately this could take a few weeks because I have not much time for this. Please be patient.
from simplephprouter.
Thanks. I'll try again, also on Apache. (I can't at the moment but I'll let you know)
from simplephprouter.
Please share your config, if you're faster than me to get this to work on nginx.
from simplephprouter.
I found the correct Nginx configuration assuming that the index.php file containing the routing instruction is contained in a subfolder called "test" and the "api" folder (with its index.php file) is a subfolder of test. The base location controls all the file in the main directory. It seems to be equals to the previous configuration but I created a new virtual host (maybe an old configuration was the problem)
`
server {
root /var/www/<main folder>;
index index.html index.htm index.nginx-debian.html index.php;
server_name <domain name>;
location / {
#Delete this if the routing index.php is in the main directory
try_files $uri $uri/ =404;
}
location /test/ {
if (!-e $request_filename){
rewrite ^(.*)$ /test/index.php;
}
}
location /test/api/ {
if (!-e $request_filename){
rewrite ^(.*)$ /test/api/index.php;
}
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
`
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.