Help needed with a mod_rewrite rule...

New to mod_rewrite? This is a good place to start.

Help needed with a mod_rewrite rule...

Postby Dark_Greg » Sat Aug 30, 2003 8:43 pm

I have a simple mod rewrite rule :
Code: Select all
RewriteEngine on
RewriteRule !\.(gif|jpg|png|css)$ index.php


Which still needs alot of work, adding more exculded files etc...but i need to add an exclusion for the "admin", so that domain/admin and all its subfolders and files are excluded from this mod_rewrite rule.

Can anyone help?
Dark_Greg
 

Postby Guest » Thu Sep 04, 2003 12:24 am

could you post a description of what you are trying to do with the first rule? It looks like you want all requests for files of those extentions to be redirected to /index.html?

If so I would suggest something like this:

RewriteRule ^.*\.(png|jpg|css)$ /index.html

ripped down it goes like this:

^ -> begin pattern match
.* -> '.' represents any single character. the '*' 0 or N of the preceding text (N > 0)
\. -> the backslash escapes the special char '.' so this will match a literal period (.)
(png|jpg|css) -> you seem to have that figured ;)
$ -> end pattern match

so that statment will match strings that have any number of characters that end in either '.png' or '.jpg' or '.css'.

Test this out for yourself, im just learning as well. Most of this info came off apache's own docs.

http://httpd.apache.org/docs/mod/mod_rewrite.html


Good Luck
Aaron
Guest
 

Postby Dark_Greg » Sat Sep 06, 2003 6:14 am

my current rule works fine, and redirects everything to index.php, unless it is an image..

but i want it to do something different

i want it to redirect everything to index.php unless it comes from the admin/ directory.
Dark_Greg
 

Re: Help needed with a mod_rewrite rule...

Postby pippo » Sat Sep 06, 2003 11:45 pm

Dark_Greg wrote:I have a simple mod rewrite rule :
Code: Select all
RewriteEngine on
RewriteRule !\.(gif|jpg|png|css)$ index.php


Which still needs alot of work, adding more exculded files etc...but i need to add an exclusion for the "admin", so that domain/admin and all its subfolders and files are excluded from this mod_rewrite rule.

Can anyone help?

Hi,

you can use this inside an .htaccess:

/.htaccess
Code: Select all
RewriteEngine On
RewriteRule !\.(gif|jpe?g|png|css)$|^admins/ index.php




:) Andrea
pippo
 
Posts: 6
Joined: Sat Sep 06, 2003 11:27 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 30 guests

cron