GithubHelp home page GithubHelp logo

Comments (8)

steampixel avatar steampixel commented on June 2, 2024 1

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.

steampixel avatar steampixel commented on June 2, 2024 1

Perfect! Thank you. I will use this maybe as a basis when creating the nginx docker example.

from simplephprouter.

steampixel avatar steampixel commented on June 2, 2024

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.

matteovisotto avatar matteovisotto commented on June 2, 2024

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.

steampixel avatar steampixel commented on June 2, 2024

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.

matteovisotto avatar matteovisotto commented on June 2, 2024

Thanks. I'll try again, also on Apache. (I can't at the moment but I'll let you know)

from simplephprouter.

steampixel avatar steampixel commented on June 2, 2024

Please share your config, if you're faster than me to get this to work on nginx.

from simplephprouter.

matteovisotto avatar matteovisotto commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.