使用htaccess的重写/重定向使单一的PHP文件可以显示数据根据GET / POST变量重写、变量、重定向、根据

2023-09-02 00:51:51 作者:俗世客

忍耐一下,因为我试图了解更多有关的.htaccess重定向规则 - 我是一个专业的UI的家伙,我尽我所能去提高我的编码技巧语言比HTML / CSS / PHP等

所以,我有什么是index.php文件,其中包含一个菜单 - pretty的简单。如果JavaScript是在用户计算机上启用进而形成如下所示的菜单中使用简单的jQuery的好东西,与具有每个环节'返回false;'应用。

我所要做的是让与JS访问的网页关掉,所以不是将用户重定向到不同的网页,我想用POST或GET变量,从每一个环节,展现了各种形式的..同样的index.php文件中 - 但该URL反映菜单选项

下面是一个例子使用的菜单项命名 - 家庭,公司,Form 1和Form:

使用JS的上,点击的上述例子只是按钮滑动的形式或包含数据向下到页面上。

重定向和转发

通过JS关闭,如果用户点击关于链接,我想重写URL是 HTTP:/ /domain.com/about 的 - 但保持index.php页面上的用户(因为它是唯一的页)和能够使用POST或GET变量来显示使用PHP

所以,在访问 http://domain.com/index.php?page=about 将显示 http://domain.com/about 在URL中,但GET变量页面传递给index.php文件文件。

希望是有道理的..我敢肯定,有很多方法可以做到这一点,所以如果你有如何改进它,通过各种手段的想法,我很乐意听到它!

再次

谢谢 复活

解决方案

的mod_rewrite

  RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^(。+)$ /index.php?page=$1 [L]
 

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

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.

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

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

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

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.

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 !

Thanks again Revive

解决方案

mod_rewrite:

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