开发者

htaccess profile URLs vs page URLs

开发者 https://www.devze.com 2023-01-27 01:36 出处:网络
I\'m working on a website using friendly URLs. We want to have www.website.com/johndoe go to John Doe\'s profile, but we also use the www.website.com/somepage form to point to pages like www.website.c

I'm working on a website using friendly URLs. We want to have www.website.com/johndoe go to John Doe's profile, but we also use the www.website.com/somepage form to point to pages like www.website.com/somepage.php. How can we accomplish this? (a physical .php page should take precedence over a user page - we'll be disallowing certain usernames anyways)

# Redirect all URLs to the corresponding PHP page
RewriteRule ^([A-Za-z0-9-_]+)$ 开发者_JAVA百科$1.php [L]

# And if that's not found, try a user's profile
RewriteRule ^([A-Za-z0-9-_]+)$ profile.php?id=$1 [L]


Something like this should work:

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

The -f pattern means "is a physical file." Not sure off the top of my head if %{REQUEST_FILENAME}.php works as I'd expect though.

0

精彩评论

暂无评论...
验证码 换一张
取 消