开发者

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

开发者 https://www.devze.com 2023-03-07 21:09 出处:网络
I would like to redirect all: <a href=\"filename\"></开发者_StackOverflowa> to <a href=\"get.php?filename\"></a>

I would like to redirect all:

<a href="filename"></开发者_StackOverflowa>

to

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

I have started to

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

But it does not work.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消