使用我们的不带查询字符串重写 htaccess 中的 php 文件
所以我有 photos.php,并且还有一些部分将被重写为 photos.php?cat=somecategory
问题是,在 .htaccess 中,我如何让它们都像
/photographs 一样工作 和 /photographs/somecategory
这样 $_GET['cat'] 变量将是 = somecategory
So I have photographs.php, and there are also sections where it will be rewritten as photographs.php?cat=somecategory
Question is, in .htaccess how do I get these both to work as such
/photographs
and
/photographs/somecategory
so that the $_GET['cat'] variable will be = somecategory
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
/photographs/(.+) 需要重定向到 photos.php?cat=$1,而 /photographs/?只会重定向到 photos.php。如果你想聪明一点,你可以将它组合起来并在一行中完成,/photograph 将直接转到 photos.php?cat=[blank]。
/photographs/(.+) will need to redirect to photographs.php?cat=$1, while /photographs/? will just redirect to photographs.php. if you want to be clever, you can combine it and do it in one line and /photograph will just go to photographs.php?cat=[blank].
首先,您必须激活
mod_rewrite
模块。以下是您需要添加到 .htaccess 文件中的内容:
只是一些简单的替换规则。您可以在网上找到大量有关它们的信息。
First of all you must have the
mod_rewrite
module activated.Here's what you need to add to your .htaccess file:
Just some simple replace rules. You can find lots of info on the web about them.