我试图将URL从example.net/customname
或example.net/customname/
重定向到example.net/my/home.php?username=customname。这本身并不复杂:URL重写以排除现有目录
RewriteRule ^([a-zA-Z0-9_-]+)$ my/home.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ my/home.php?username=$1
不过,我想我的排除现有的目录和文件,如example.net/about/
和example.net/files
。我不能完全弄清楚如何使用RewriteCond(我是否需要多个重写conds?),以便排除诸如example.net/about/
之类的项目被重写为example.net/home.php?username=about
。我怎样才能做到这一点?
谢谢!
编辑:这里是确切的解决方案...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ my/home.php?url=$1 [NC,L]
关于你的编辑:你为什么使用两套完全不同的规则,其唯一的区别是单个字符?它是冗长而低效的,所以我建议使用选项限定符(问号)作为localshred,并在我们的答案中做过。 – 2009-08-20 01:40:03
很对,我改变了我的回答以反映。 – Wickethewok 2009-08-20 14:00:50