如何将请求的 URL 作为 $_GET 参数的任何页面重写为索引页面

发布于 2024-12-24 22:14:23 字数 294 浏览 1 评论 0 原文

这里已经讨论了类似的事情,但这略有不同。

如何告诉 .htaccess 使用站点索引页面重写任何请求的页面(无论距站点根目录的深度如何),但使用请求的 URL 作为 $_GET 参数,以便 php 根据其内容进一步处理它,或者取决于 URL 本身。

我正在尝试类似的事情

Options +FollowSymlinks
RewriteEngine on 
RewriteRule ^(.*) index.php?page=$1

,但显然我做错了。

提前致谢。

Something similar had been discussed here, but this is slight different.

How to tell .htaccess to rewrite any requested page (regardless of it's depth from the site root) with site's index page, but with requested URL as a $_GET parameter, so it can be further handled by php, depending on it's contents, or depending on URL itself.

I was trying something like

Options +FollowSymlinks
RewriteEngine on 
RewriteRule ^(.*) index.php?page=$1

but obviously I do something wrong.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

塔塔猫 2024-12-31 22:14:23

尝试使用您的正则表达式。也许是这样的:

RewriteRule ^([a-zA-Z0-9\-]+)([\/]*)$ index.php?page=$1 [NC,QSA,L]

Try working on your RegEx. Maybe something like this:

RewriteRule ^([a-zA-Z0-9\-]+)([\/]*)$ index.php?page=$1 [NC,QSA,L]
何以畏孤独 2024-12-31 22:14:23

基本上,您可以使用在线工具生成重写代码,例如 http://www.webtoolhub .com/tn561403-htaccess-url-rewrite.aspx 通过输入所需的参数。只需输入 url 结构,它就会编写 .htaccess 代码,您可以根据需要使用或修改该代码。

Basically you can generate the rewrite code using an online tool like http://www.webtoolhub.com/tn561403-htaccess-url-rewrite.aspx by entering the desired parameters. Just put the url structure and it will write the .htaccess code that you can use or modify according to your needs.

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