使用我们的不带查询字符串重写 htaccess 中的 php 文件

发布于 2024-09-28 05:08:37 字数 231 浏览 1 评论 0原文

所以我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱本泡沫多脆弱 2024-10-05 05:08:37

/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].

残花月 2024-10-05 05:08:37

首先,您必须激活 mod_rewrite 模块。

以下是您需要添加到 .htaccess 文件中的内容:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^photographs$ photographs.php [NC]
RewriteRule ^photographs/(.*)$ photographs.php?cat=$1 [NC]

只是一些简单的替换规则。您可以在网上找到大量有关它们的信息。

First of all you must have the mod_rewrite module activated.

Here's what you need to add to your .htaccess file:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^photographs$ photographs.php [NC]
RewriteRule ^photographs/(.*)$ photographs.php?cat=$1 [NC]

Just some simple replace rules. You can find lots of info on the web about them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文