Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Commit

Permalink
Rewrite Rules: Add Support php server, fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
jgauthi committed Apr 17, 2022
1 parent 16d499b commit 33a9c4f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ This script handles the following parameters, where basically all of them are op
All default value is set on [config.ini](./config.ini), you can edit this file for your project, and add several parameters for different folders (you must create new section on ini file).


## Htaccess Url Rules
### Auto-Image with custom name / size
## Url Rules
### Support with Apache and Htaccess
#### Auto-Image with custom name / size
If you use apache, a [.htaccess](./.htaccess) is available with these rules:

```text
Expand All @@ -44,7 +45,7 @@ Classic usage on root folder:
```


### Virtual support folder and sub folder with specific rules (optional)
#### Virtual support folder and sub folder with specific rules (optional)
You can use the [.htaccess](./.htaccess) rules for support **virtual folder and sub folder** (IMG use precedents name convention):

```text
Expand Down Expand Up @@ -77,6 +78,32 @@ type=jpg
font=RobotoMono-Regular.ttf
```

## Local php-server
If you use local php-server, you can create a file [router.php](./.example_phpserver_router.php) on your project on public/web folder _(this file use your index.php)_, and edit this file for use it.

```php
// Edit this const
const ROUTER_EXPREG = '#^(/images/)(film)?/?#i';
const FULLPATH_DUMMY_IMG_GENERATOR = '/path/to/PHP-Dummy-Image-Generator/index.php';

if (preg_match(ROUTER_EXPREG, $_SERVER['REQUEST_URI'], $extract)) {
$_GET['cfg'] = $extract[2];
// var_dump($extract);return true; // debug
require_once FULLPATH_DUMMY_IMG_GENERATOR;
return true;

} //...
```

You can add several condition for each url rules, add CFG folder on [config.ini](./config.ini) and edit the router template (for more details, look at _Virtual support folder and sub folder with specific rules_).
For use this router.php, you must launch for start the php-server:

```shell
cd root_project/
cd public ; php -S localhost:8000 router.php
# Or web folder, depending on your project
```


## License & Credits
Please see the [license file](./LICENSE) for more information.
Expand Down
15 changes: 15 additions & 0 deletions example_phpserver_router.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
const ROUTER_EXPREG = '#^(/images/)(film)?/?#i';
const FULLPATH_DUMMY_IMG_GENERATOR = '/path/to/PHP-Dummy-Image-Generator/index.php';

if (preg_match(ROUTER_EXPREG, $_SERVER['REQUEST_URI'], $extract)) {
$_GET['cfg'] = $extract[2];
// var_dump($extract);return true; // debug
require_once FULLPATH_DUMMY_IMG_GENERATOR;
return true;

} elseif (preg_match('#\.(?:png|jpe?g|gif|js|css|mp3|ogg|mp4|avi|webm|webp)$#', $_SERVER['REQUEST_URI'])) {
return false;
} else {
require_once __DIR__.'/index.php';
}

0 comments on commit 33a9c4f

Please sign in to comment.