In my apache site configuration file, I have the following. The rewrite rule works fine, but the rule is applying to existing directories which my rewrite conditions were supposed to fix. Here is my rewrite script:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9_]+)/?$ test.php?n=$1 [L]
So example.com/username
works great and uses test.php
, but also when I enter an existing sub-directory that has an index.php
file in it, aka, example.com/myDirectory/
still uses test.php. Any idea what's wrong with my script? Thanks.
Below is a rewrite log for request myDirectory
which is an existing directory:
(2) init rewrite engine with requested uri /myDirectory/
(1) pass through /myDirectory/
(3) [perdir /var/www/] strip per-dir prefix: /var/www/myDirectory/ -> myDirectory/
(3) [perdir /var/www/] applying pattern '^tag/([a-zA-Z0-9-]+)/?$' to uri 'myDirectory/'
(3) [perdir /var/www/] strip per-dir prefix: /var/www/myDirectory/ -> myDirectory/
(3) [perdir /var/www/] applying pattern '^([a-zA-Z0-9_]+)/?$' to uri 'myDirectory/'
(2) [perdir /var/www/] rewrite 'myDirectory/' -> 'test.php?n=myDirectory'
(3) split uri=test.php?n=myDirectory -> uri=test.php, args=n=myDirectory
And here is the log for request bananas
which is meant to use the rewrite (and does):
(2) init rewrite engine with requested uri /bananas
(1) pass through /bananas
(3) [perdir /var/www/] strip per-dir prefix: /var/www/bananas -> bananas
(3) [perdir /var/www/] applying pattern '^tag/([a-zA-Z0-9-]+)/?$' to uri 'bananas'
(3) [perdir /var/www/] strip per-dir prefix: /var/www/bananas -> bananas
(3) [perdir /var/www/] applying pattern '^([a-zA-Z0-9_]+)/?$' to uri 'bananas'
(2) [perdir /var/www/] rewrite 'bananas' -> 'test.php?n=bananas'
(3) split uri=test.php?n=bananas -> uri=test.php, args=n=bananas