可能的重复:
.htaccess 创建友好的 URL。需要帮助 https://stackoverflow.com/questions/3033407/htacces-to-create-friendly-urls-help-needed
我正在使用 ids 来显示成员的记录(个人资料)。
So /profile.php?id=1
显示id为1的会员的数据。
但这些网址很丑陋,而且对 SEO 也不友好。
我想将网址更改为格式profiles/membername
(membername 是已存储在数据库中的每个成员的唯一别名)。
如何通过.htaccess实现这个链接结构?
这需要安装apache的mod_rewrite模块。你想要的可以通过下面的代码来实现:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^profiles/(.*)?$ profile.php?id=$1
</IfModule>
例子:
www.yourwebsite.com/profiles/1234 -> www.yourwebsitename.com/profile.php?id=1234
如果您想要更多变量,只需修改上面的行,如下所示:
RewriteRule ^profiles/(.*)/(.*)?$ profile.php?id=$1&var2=$2
只需编辑 .htaccess 文件并添加上述行,确保在进行任何修改之前创建 .htaccess 的备份。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)