设置 URL 为 firstname.lastname
Set URL with firstname.lastname
我已经尝试使用 .htaccess
RewriteRules,但它不会像我想象的那样工作。
我的重写规则:
RewriteRule ^login?$ login.php [NC,L]
RewriteRule ^me profile.php?user-id=me [QSA,L]
RewriteCond !^(index\.php)
RewriteRule ^([A-Za-z-\s]+).([A-Za-z-\s]+)$ profile.php?user-id=. [QSA,L]
RewriteRule ^settings?$ settings.php [NC,L]
我的问题是如果用户键入服务器 URL (localhost/box4/
) 它将显示 index.php
.
我提到的是获取用户名;示例:john.doe
就像在 Facebook 中一样,它应该分隔用户名:firstname.lastname
(用点分隔)
我决定从 PHP:
生成用户名
foreach(explode(".",$_GET['user-id']) as $val1){
$userName .= $val1." ";
}
$userName = ucwords($userName);
我希望它不应该使用 index.php
。会出现错误的结果:firstname
= index
和 lastname
= php
我可以做些什么来解决这个问题?
你的规则是这样的:
RewriteRule ^(login|settings)/?$ .php [NC,L]
RewriteRule ^me/?$ profile.php?user-id=me [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond !^index [NC]
RewriteRule ^([A-Za-z-\s]+)\.([A-Za-z-\s]+)$ profile.php?user-id=. [QSA,L]
我已经尝试使用 .htaccess
RewriteRules,但它不会像我想象的那样工作。
我的重写规则:
RewriteRule ^login?$ login.php [NC,L]
RewriteRule ^me profile.php?user-id=me [QSA,L]
RewriteCond !^(index\.php)
RewriteRule ^([A-Za-z-\s]+).([A-Za-z-\s]+)$ profile.php?user-id=. [QSA,L]
RewriteRule ^settings?$ settings.php [NC,L]
我的问题是如果用户键入服务器 URL (localhost/box4/
) 它将显示 index.php
.
我提到的是获取用户名;示例:john.doe
就像在 Facebook 中一样,它应该分隔用户名:firstname.lastname
(用点分隔)
我决定从 PHP:
生成用户名foreach(explode(".",$_GET['user-id']) as $val1){
$userName .= $val1." ";
}
$userName = ucwords($userName);
我希望它不应该使用 index.php
。会出现错误的结果:firstname
= index
和 lastname
= php
我可以做些什么来解决这个问题?
你的规则是这样的:
RewriteRule ^(login|settings)/?$ .php [NC,L]
RewriteRule ^me/?$ profile.php?user-id=me [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond !^index [NC]
RewriteRule ^([A-Za-z-\s]+)\.([A-Za-z-\s]+)$ profile.php?user-id=. [QSA,L]