Arman
Arman

Reputation: 4636

RewriteRule for URLs that do not end with dot html/php

I would like to redirect all:

<a href="filename"></a>

to

<a href="get.php?filename"></a>

I have started to

RewriteRule  !\.(html|php)$  /get.php?file=$1 [PT]

But it does not work.

Upvotes: 2

Views: 1520

Answers (2)

Salman Arshad
Salman Arshad

Reputation: 272246

I've tested this regexp in PHP it should work in mod_rewrite but I have not tested it and seems to work in mod_rewrite too:

RewriteRule ^(.+)(?<!\.php)(?<!\.html)$ /get.php?file=$1

The rule will rewrite all URLs except those that end with .php or .html.

Upvotes: 6

Orbling
Orbling

Reputation: 20612

The most basic way to handle that is:

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

Which will redirect everything, setting file to the value of the path.

Upvotes: 1

Related Questions