htaccess配置文件URL与页面URL

时间:2010-11-25 04:04:17

标签: php apache .htaccess

我在使用友好网址的网站上工作。我们希望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]

1 个答案:

答案 0 :(得分:3)

这样的事情应该有效:

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([A-Za-z0-9-_]+)$ $1.php [L]

-f模式means“是一个物理文件。”如果%{REQUEST_FILENAME}.php正如我所期望的那样工作,那么我不确定是不是最重要的。