我在使用友好网址的网站上工作。我们希望www.website.com/johndoe
转到John Doe的个人资料,但我们也使用www.website.com/somepage
表单指向www.website.com/somepage.php
这样的网页。我们怎样才能做到这一点? (物理.php页面应优先于用户页面 - 我们将禁止某些用户名)
# Redirect all URLs to the corresponding PHP page
RewriteRule ^([A-Za-z0-9-_]+)$ $1.php [L]
# And if that's not found, try a user's profile
RewriteRule ^([A-Za-z0-9-_]+)$ profile.php?id=$1 [L]
答案 0 :(得分:3)
这样的事情应该有效:
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([A-Za-z0-9-_]+)$ $1.php [L]
-f
模式means“是一个物理文件。”如果%{REQUEST_FILENAME}.php
正如我所期望的那样工作,那么我不确定是不是最重要的。