Is there a way to detect regular expression support in a htaccess file?

1

I use to following rewrite rule to pass the whole url to an php script:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*?)$ index.php?rewriteUrl=$1 [QSA,L]

On some servers, I have to use

RewriteRule ^(.*)$ index.php?rewriteUrl=$1 [QSA,L]

instead (the ? is missing).

Is there a way to make the server handle this automatically? In form of a fallback/try-catch or something like this?

Blauesocke

Posted 2012-10-30T17:09:18.737

Reputation: 113

I can't say I understand your question or the point of having the ? in the expression. For information on regular expression usage in mod_rewrite, please see the Apache documentation.

– quentinxs – 2012-11-01T16:53:27.017

Answers

1

If you know the different version numbers between the two servers, use mod_version to do this. For instance, if 2.3+ uses the ?:

<IfVersion >= 2.3>
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*?)$ index.php?rewriteUrl=$1 [QSA,L]
</IfVersion>

<IfVersion < 2.3>
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewriteUrl=$1 [QSA,L]        
</IfVersion>

Use ServerSignature to have the version info sent to the client.

Paul Sweatte

Posted 2012-10-30T17:09:18.737

Reputation: 613