2010-11-25 77 views
2

我正在使用友好网址的网站上工作。我们希望www.website.com/johndoe转到John Doe的个人资料,但我们也使用www.website.com/somepage表单指向www.website.com/somepage.php这样的网页。我们怎样才能做到这一点? (物理PHP页面应该优先于用户页面 - 我们会禁止反正一定的用户名)htaccess个人资料网址与网页网址

# 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

你可能想通过`/ user/johndoe`来防止... – SeanJA 2010-11-25 04:11:22

回答

3

像这样的东西应该工作:

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

-f模式means“是物理文件“。不知道,如果%{REQUEST_FILENAME}.php正如我所预料的那样工作,那么我的头顶就是这样。