# Web Server Control
The `System.WebServer` unit provides global control over the web server hosting the scripts. It is typically used in the server startup script (`.startup.pas`).
## WebServer Object
The `WebServer` object allows controlling global server settings, such as URL rewriting.
| Member | Description |
| :--- | :--- |
| `SetURLRewriteRulesJSON(json)` | Configures URL rewriting rules using a JSON string. |
| `GetURLRewriteRulesJSON()` | Returns the current rewrite rules as a JSON string. |
| `CompiledPrograms()` | Returns a list of all scripts currently compiled in memory. |
| `CompilationInfoJSON(fileName)` | Returns compilation details for a specific script. |
## URL Rewriting
You can define rules to transparently rewrite incoming URLs. This is typically done in the server startup script (`.startup.pas`).
### Rule Format (JSON)
The configuration is an array of rule objects:
* `pattern`: The URL pattern to match. Supports `*` as a wildcard (matches until the next separator in the pattern).
* `rewrite`: The target URL. Supports `$1`, `$2`, ... placeholders corresponding to the `*` wildcards.
### Example
```pascal
// NO_RUN
uses System.WebServer;
WebServer.SetURLRewriteRulesJSON(#'[
{ "pattern": "/lang/*", "rewrite": "/doc.dws?id=lang/$1" },
{ "pattern": "/example/*", "rewrite": "/examples/view.dws?example=$1" },
{ "pattern": "/ref/*", "rewrite": "/ref/index.dws?id=ref/$1" }
]');
```
Web Server Control
The System.WebServer unit provides global control over the web server hosting the scripts. It is typically used in the server startup script (.startup.pas).
WebServer Object
The WebServer object allows controlling global server settings, such as URL rewriting.
Member
Description
SetURLRewriteRulesJSON(json)
Configures URL rewriting rules using a JSON string.
GetURLRewriteRulesJSON()
Returns the current rewrite rules as a JSON string.
CompiledPrograms()
Returns a list of all scripts currently compiled in memory.
CompilationInfoJSON(fileName)
Returns compilation details for a specific script.
URL Rewriting
You can define rules to transparently rewrite incoming URLs. This is typically done in the server startup script (.startup.pas).
Rule Format (JSON)
The configuration is an array of rule objects:
pattern: The URL pattern to match. Supports * as a wildcard (matches until the next separator in the pattern).
rewrite: The target URL. Supports $1, $2, ... placeholders corresponding to the * wildcards.