重写页面和用户配置文件的规则

时间:2014-04-11 14:08:12

标签: .htaccess

我无法弄清楚如何重写此网址

http://localhost/site/page.php?id=[pagetitle]


http://localhost/site/page/title

和 用户个人资料

http://localhost/site/profile.php?username=username


http://localhost/site/profile/username

这是我正在使用的代码:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^profile(.*)$ profile.php?username=$1
RewriteRule ^(.*)$ page.php?title=$1

3 个答案:

答案 0 :(得分:1)

这会将输入localhost / site / page / title重写为loacalhost / site / page.php?id = [pagetitle]

    RewriteRule ^localhost/site/(.+)$ site/page.php?id=$1
    RewriteRule ^localhost/site/profile/(.+)$ site/profile.php?username=$1

答案 1 :(得分:0)

这应该有效

RewriteRule ^([a-zA-Z0-9 _-] +)$ profile.php?username = $ 1

RewriteRule ^([a-zA-Z0-9 _-] +)/ $ profile.php?username = $ 1

答案 2 :(得分:0)

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^profile/(.*)$ profile.php?username=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/(.*)$ page.php?title=$1

假设/ site /目录下的.htaccess