Christian Seiler: mod_rewrite: Exclude directories from rewrite rule

Beitrag lesen

Hi,

RewriteEngine on
RewriteCond %{REMOTE_ADDR} !=111.222.333.444
RewriteCond %{REQUEST_URI} !=/303.php [NC]
RewriteRule ^(.*)$ /303.php [R=302,NC,L]

Very similar to the way you already excluded /303.php itself:

RewriteEngine on  
RewriteCond %{REMOTE_ADDR} !=111.222.333.444  
RewriteCond %{REQUEST_URI} !=/303.php [NC]  
RewriteCond %{REQUEST_URI} !^/users(/|$)  
RewriteRule ^(.*)$ /303.php [R=302,NC,L]

Here, the ^/users(/|$) is a regular expression (saying "/users" followed either by "/" or nothing, so "/users", "/users/", "/users/..." will match but "/usersfoo" will not) instead of a fixed string like =/303.php.

Regards,
Christian

PS: Please note that this is usually a German forum and while quite a few people here speak English, generally you may have more luck finding help in English elsewhere.