我无法弄清楚如何重写此网址
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
答案 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