Regex to match a series of files in .htaccess

It will be a stupid question, I think, but I don’t see what is happening here. I want to map a specific set of URIs through a regular expression in a .htaccess file.

I want the following

  • All files that do not contain.
  • all files ending with .htm / .html
  • all files ending with .php

So:

^[^.]+$

works to match all dotless files in a URI.

\.html?$

matches all .html / .htm files

(^[^.]+$)|(\.html?$)

seems to work by combining how

(^[^.]+$)|(\.html?$)|(\.php$)

cannot combine things with matching files ending in php-case. test.jpg, for example, matches now, while it shouldn't.

I have to miss something obvious. What is it? Thank.

Update: here is the whole context that I used:

### REWRITE RULES ###
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (^[^.]+$)|(\.html?$)|(\.php$) bootstrap.php [L,QSA]

bootstrap.php contains:

echo "testing bootstrap";

Request non-existent .jpg

http://localhost/test.jpg

gives me this result:

testing bootstrap
...

2:

, :

RewriteRule \.php$ bootstrap.php [L,QSA]

, . test.jpg. .htaccess, ... , .htaccess, , :

AddType application/x-httpd-php .html
AddType application/x-httpd-php .xml
DirectoryIndex index.php
ErrorDocument 404 /errors/404.php

: ( 8 ...)

, .
@mario, .
. :

rewrite.log:

strip per-dir prefix: D:/Web_Root/test.jpg -> test.jpg
applying pattern '\.php$' to uri 'test.jpg'
pass through D:/Web_Root/test.jpg
strip per-dir prefix: D:/Web_Root/errors/404.php -> errors/404.php
applying pattern '\.php$' to uri 'errors/404.php'
RewriteCond: input='D:/Web_Root/errors/404.php' pattern='!-d' => matched
rewrite 'errors/404.php' -> 'bootstrap.php'
...

, , 404 *.php, *.jpg . Ah Bats, ...

, :

RewriteRule ([^4]?[^0]?[^4]\.php) bootstrap.php [L,QSA]

, :

RewriteRule (^[^.]+$)|(\.html?$)|([^4]?[^0]?[^4]\.php) bootstrap.php [L,QSA]

: .

+5
3

[, , .]

mod_rewrite , RewriteLog. httpd.conf VirtualHost, , , . Apache URL. , , Apache , .

, - Alias Redirect FileMatch. error.log access.log .

, Nanoweb Apache. mod_rewrite, , , PHP preg_match PCRE backend. ( , .)

+1

?

(^[^.]+$)|\.(html?$|php$)

* : , . :

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} ^[^.]+$ [OR]
RewriteCond %{REQUEST_FILENAME} ^.*\.(html?|php)$
RewriteRule ^(.*)$ bootstrap.php [L,QSA]
0

Okay, so it looks like your rewriting IS is working ... you can see your "test bootstrap" message. The warning "cannot change the title" is not related. This means that you are trying to do something like session_start () or header () or something else after you already output something (maybe this is the message "test bootstrap")

0
source