andufo andufo - 4 months ago 23
Apache Configuration Question

How to avoid RewriteRule for specific directory?

This is my current

.htaccess
data.

# permalinks
RewriteEngine on

# users
RewriteRule ^([a-z0-9_-]{2,15})$ /user.php?username=$1 [QSA,L]


Which obviously means that

http://testsite.net/asantos


is parsed as:

http://testsite.net/user.php?username=asantos


The website also has an inc directory in the root, and if I open this url

http://testsite.net/inc/


it actually redirects to:

http://testsite.net/inc/?username=inc


How can I avoid that behavior for existing directories that are in the root of the website?

Answer

How can I avoid that behavior for existing directories that are in the root of the website?

Use:

# permalinks
RewriteEngine on

# skip all files and directories from rewrite rules *below*
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([a-z0-9_-]{2,15})$ /user.php?username=$1 [QSA,L]

# more rules here