使用 htaccess 重写/重定向,以便单个 PHP 文件可以根据 GET/POST 变量显示数据 [英] Using htaccess rewrite/redirect so single PHP file can display data according to GET/POST variables

查看:17
本文介绍了使用 htaccess 重写/重定向,以便单个 PHP 文件可以根据 GET/POST 变量显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请耐心等待我尝试了解有关 .htaccess 重定向规则的更多信息 - 我的职业是 UI 专家,我正在尽最大努力提高我的编码技能,而不是 HTML/CSS/PHP 等语言

Bear with me as I try to learn more about .htaccess redirect rules - I'm a UI guy by profession and I'm doing my best to enhance my coding skills languages other than HTML/CSS/PHP, etc

所以,我拥有的是一个包含菜单的 index.php 文件 - 非常简单.如果在用户计算机上启用了 Javascript,则使用简单的 jQuery 好东西在菜单下方显示表单,每个链接都有一个返回假;"已申请.

So, what I have is an index.php file that contains a menu - pretty simple. If Javascript is enabled on the users computer then forms are shown below the menu using simple jQuery goodies, with each link having a 'return false;' applied.

我想要做的是在关闭 JS 的情况下使页面可访问,因此我不想将用户重定向到不同的页面,而是想使用每个链接中的 POST 或 GET 变量来显示各种表单.在同一个 index.php 文件中 - 但让 URL 反映菜单选择

What I am trying to do is make the page accessible with JS turned off, so instead of redirecting the user to a different page, I would like to use POST or GET variables from each link, to show the various forms.. within the same index.php file - but have the URL reflect the menu choice

以下是使用名为 - Home、About、Form1 和 Form2 的菜单项的示例:

Here is an example using menu items named - Home, About, Form1 and Form2:

启用 JS 后,单击上面的示例按钮只需将表单或包含数据的内容向下滑动到页面上.

With JS on, clicking on of the above example buttons simply slides the form or containing the data down onto the page.

关闭 JS,如果用户单击关于"链接,我想将 URL 重写为 http://domain.com/about - 但将用户保留在 index.php 页面上(因为它是唯一的页面)并且能够使用 POST 或 GET 变量来显示正在使用的 PHP.

With JS off, if the user clicks the 'About' link, I would like to rewrite the URL to be http://domain.com/about - but keep the user on the index.php page (since it is the only page) and be able to use POST or GET variable to show the using PHP.

因此,访问 http://domain.com/index.php?page=about会显示http://domain.com/about 在 URL 中,但将 GET 变量 'page' 传递给 index.php文件.

So, accessing http://domain.com/index.php?page=about would show http://domain.com/about in the URL but pass the GET variable 'page' to the index.php file.

希望这是有道理的..我相信有很多方法可以做到这一点,所以如果你有关于如何改进它的想法,无论如何,我很乐意听到它!

Hope that makes sense.. and I'm sure there are many ways to accomplish this, so if you have ideas of how to improve on it, by all means, I'd love to hear it !

再次感谢复活

推荐答案

mod_rewrite:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php?page=$1 [L]

这篇关于使用 htaccess 重写/重定向,以便单个 PHP 文件可以根据 GET/POST 变量显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆