Frage

I want to make reference to a variable called "foo" (with value "bar")

SetEnv foo bar

within a RewriteRule

 RewriteRule ^([^/]*)/([^/]*)/$ /{foo}.php?p=$1&id=$2 [L]

so that it literally reads as:

RewriteRule ^([^/]*)/([^/]*)/$ /bar.php?p=$1&id=$2 [L]

How is this possible?

War es hilfreich?

Lösung

Tricky but can be done by combining mod_setenvif and mod_rewrite.

Use this code in your root .htaccess:

RewriteEngine On

SetEnvIf Host ^ foo=bar

RewriteRule ^([^/]+)/([^/]+)/?$ /%{ENV:foo}.php?p=$1&id=$2 [L]
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top