.htaccess RewriteCond

hi all!
i need something very simple like this:

domain.com/members/george
the output of this url must be generated by exe.php which is under members folder

but if a .php file or a .js file is called, then they must work alone without going to exe.php

so i made a .htaccess like this:

RewriteEngine On
RewriteCond %{THE_REQUEST} !^.\.php$
RewriteCond %{THE_REQUEST} !^.
\.js$
RewriteRule (.*) exe.php [L,NS]

but it does not work as i want :slight_smile:
can somebody help me?

You should include the members directory in the RewriteRule (assuming the .htaccess is in the DocumentRoot of the website, which it usually is).

Also, don’t use the ANYTHING atom (.*), but match only letters, digits and hyphens: [\w\d\-]+


RewriteEngine On
RewriteCond %{THE_REQUEST} !^.*\\.php$
RewriteCond %{THE_REQUEST} !^.*\\.js$
RewriteRule ^[COLOR="Red"]members/[/COLOR]([\\w\\d\\-]+) [COLOR="Red"]/members/[/COLOR]exe.php [L,NS]

Don’t you need to supply a parameter to exe.php btw, like exe.php?username=george ?
If you do, you should change the RewriteRule to


RewriteRule ^members/([\\w\\d\\-]+) /members/exe.php[COLOR="Red"]?username=$1[/COLOR] [L,NS]

i tried both rewriterules but none worked :rolleyes:
i think there is a mistake in RewriteCond. because i uploaded a .jpg file and the jpg file worked when i requested. (it should not work, because only php and js files are allowed due to htaccess)

ok i solve this issue :slight_smile:
code should be like this:

RewriteEngine On
RewriteRule !^.*\.(php|js)$ exe.php [L,NS]

thank you for your reply ScallioXTX i solved it with your idea :slight_smile:

mitsy,

Actually, your use of ^.* in the regex is wasteful as Apache must go match everything in the {REQUEST_URI} string up to the dot character, too. Just omit those three characters (to optimize your regex).

For others (I had to look it up), the NS flag is to prevent an already redirected {REQUEST_URI} from being redirected again.

Regards,

DK

you’re right dklynn,

RewriteEngine On
RewriteRule !\.(php|js|css|gif|png)$ exe.php [L,NS]

this also worked and should be faster… i’ll dig in more about the flags, if NS is to prevent a multiple redirection, i should remove it also… thanks for your notice friend :cool:

No problem, mitsy!

Regards,

DK