0

I'm using regex in a htaccess file to catch /[username] and re-direct this to a username page, for example, mywebsite.com/john will forward to mywebsite.com/username?u=john. This works, but I now want to exclude anything that matches a directory which exists. So, if someone goes to mywebsite.com/sign-up, this is EXCLUDED for the re-direction, because that directory (/sign-up) exists. Is that possible, and is it normal practice? Thank you.

Edit: Ideally I don't want to have to exclude every existing directory manually. I'd like it to be automatic for all existing directories.

4

1 回答 1

0

在它之前使用重写条件。!-f 表示不存在的文件,!-d 表示不存在的目录。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]+)$ username?u=$1 [L]
于 2012-05-07T17:06:14.797 回答