域名/URL 屏蔽
我有一个网站,它将一些 GET 变量传递到 PHP 中的不同页面。我的问题是,现在我有一个带有变量的网址,即index.php?category=categoryname,这不是很容易记住。
有什么方法可以将 URL 更改为 /categoryname 之类的内容,而无需复制页面并存储在文件夹中?但还允许用户输入 /categoryname 并重定向到正确的页面?
I have a website that passes some GET variables to different pages in PHP. My issue is that now I have a url with variables i.e. index.php?category=categoryname and that's not very memorable.
Is there any way I can change the URL to something like /categoryname instead without duplicating the page and storing in folders? But also allow users to type in /categoryname and be redirected to the correct page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
.htaccess Apache mod_rewrite,几乎每个专业的动态网站都使用这种方法(比如stackoverflow)。
该方法在这篇文章中得到了充分的解释,比我在这个答案中解释的要好得多盒子。
.htaccess Apache mod_rewrite, almost every professional dynamic website uses this method (like stackoverflow).
The method is fully explained in this article far better then I could ever explain it in this answer box.
您应该考虑在
.htaccess
文件中编写一些 apacheMod_Rewrite
规则。You should look into writing some apache
Mod_Rewrite
rules in a.htaccess
file.此处讨论了该解决方案:
RewriteRule ^cat/([0-9]+)$
/index.php?category=$1
www.example.com/cat/123
www.example.com/index.php?category
The solution is discussed here:
RewriteRule ^cat/([0-9]+)$
/index.php?category=$1
www.example.com/cat/123
www.example.com/index.php?category=123