我目前在测试网站设置上有配置文件,可以通过以下格式查看:
example.com/profile.php?u=username
我想使用这种格式:
example.com/profile/username
我如何将其username
视为php中的变量而不是文件?
您需要使用apache mod_rewrite。
.htaccess
在网站的根目录上创建一个名为的文件,并添加以下内容:
RewriteEngine on
RewriteRule ^/profile/(.*)$ /profile.php?u=$1 [QSA,L]
现在,如果您导航到:
example.com/profile/usertest
apache会将变量发送usertest
到profile.php?u=usertest
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句