我有这样一个网址:
http://www.site.com/profile.php?id=$id
而且我希望它落得像:
http://www.site.com/$id
我怎么能在PHP或htaccess的做到这一点?
我有这样一个网址:
http://www.site.com/profile.php?id=$id
而且我希望它落得像:
http://www.site.com/$id
我怎么能在PHP或htaccess的做到这一点?
您将需要创建htaccess的重写规则如
RewriteRule ([0-9]+) profile.php?id=$1 [L]
这将改写以0-9字符profile.php任何东西,通过查询字符串的数量。所以,你可以做
site.com/1
这将是
site.com/profile.php?id=1
N多的讨论已经在这里了。无论如何,在这里。 :)
你htacces重写规则,
RewriteEngine on
RewriteBase/
RewriteRule ^([0-9]+)$ profile.php?id=$1 [L]
方式把PHP文件的链接,
<a href="http://www.site.com/$id">Your URL</a>
确保您的值替换$ ID。
仅供参考,http://www.site.com/profile.php?id=$id
也可以工作,避免使用它&使用掩码URL像我上面引用。 :)
RewriteEngine在 RewriteRule ^([^ /] *)\。html $ /profile.php?id=$1 [L] – Pratik
使用htacess编写您的URL方案并将其链接到您的php文件中根据URL方案。请参阅http://dzineblog.com/2012/05/build-a-custom-url-structure-with-htaccess-rewrites.html –
谢谢大家。我对技术问题感到困惑。我很感谢你回答我的常见问题。 – Kragalon