删除GET变量和.PHP使用htaccess的

编程入门 行业动态 更新时间:2024-10-24 04:33:22
本文介绍了删除GET变量和.PHP使用htaccess的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图解决一些htaccess的问题,我不能够达成解决方案。 我有以下的html:

I'm trying to solve some htaccess question and I'm not able to reach the solution. I have the following html:

< A HREF =www.site/home.php?Idi=英语>英语< / A> < A HREF =www.site/home.php?Idi=法语>法语< / A>

<a href="www.site/home.php?Idi="English">English</a> <a href="www.site/home.php?Idi="Française">Française</a>

和目标是,用户只要获得其地址栏中输入:

and the goal is that user just gets in its address bar:

www.site/home/English

www.site/home/Française

显然,GET变量应该到达home.php进行处理。

Obviously, the get variables should arrive to home.php to be processed.

此外,该网站还有其他页面扩展名为.php然后我删除每个扩展名:

Also, the site has other pages with extension .php and I got delete each extension with:

选项+了FollowSymLinks RewriteEngine叙述上 的RewriteBase / 的RewriteCond%{} REQUEST_FILENAME -f .PHP 重写规则^%{REQUEST_URI}的.php [L]

Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^ %{REQUEST_URI}.php [L]

另外,我想起始页:

www.site/home.php

将显示为:

www.site/home/English

我看到有关它很多的教程和职位,但我不能够解决这个问题。

I have seen a lot of tutorials and posts concerning it, but I am not able to solve it.

任何帮助将是AP preciated,谢谢

Any help would be appreciated, thanks

EDITED 的

EDITED:

最后,UnskilledFreak建议我,我改变了原来的链接:

Finally, as UnskilledFreak suggested me, I changed the original links to:

<a href="www.site/home/English">English</a> <a href="www.site/home/Française">Française</a>

和htaccess的是如下:

and the htaccess is as:

Options +FollowSymLinks RewriteEngine on RewriteBase / #Receive site/home/Language and internally processes site/home.php?Idi=Language RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^home/(English)/?$ home.php?Idi=English [QSA,NC,L] RewriteRule ^home/(Française)/?$ home.php?Idi=Française [QSA,NC,L] #Receive site/something and internally goes to site/something.php RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^ %{REQUEST_URI}.php [L]

要避免的css,js和在新的页面加载等环节的崩溃,我添加了一个 / 前的HTML的每一条路径。

To avoid the crash of css, js and other links loaded in new pages, I added a / before every path of the html.

.htaccess中被放在根。 在家的文件夹不服务器存在。

The htaccess is placed in the root. The 'home' folder doesn't exist in the server.

推荐答案

像注释说明,编辑后的邮政以上,它会工作;)

Like the comments explain AND the edited Post above, it'll work ;)

但这里是另一种解决方案获取和工作过:

but here is another solution i get and works too:

在我的document_root我添加了一个名为测试,在那里我已经得到了4个文件具有以下内容的文件夹:

in my document_root i've added a folder called test, in there i've got 4 files with following content:

的.htaccess

Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . /test/index.php [L]

的index.php - 一个包装重写和testlinks

index.php - a wrapper for rewrite and testlinks

echo' <!DOCTYPE html> <head> <title>Rewrite Test</title> <link rel="stylesheet" type="text/css" href="/test/style.css"> </head> <body> <a href="/test/home/english">English</a><br> <a href="/test/home/francaise">Francaise</a><br> '; $get = explode("/",$_SERVER["REQUEST_URI"]); $get = array_slice($get,2); // ignoring first empty key and folder 'test' #echo "<pre>".print_r($get,true)."</pre>"; if(file_exists($get[0].".php")) require($get[0].".php"); else echo 'file '.$get[0].'not found'; echo' </body> </html>';

home.php - 按要求

<?php echo 'in home.php, you have choosen:'.$get[1]; ?>

的style.css - 仅作为测试文件访问将工作

style.css - only as test that file access will work

body { color:#ff8800; font-weight:bold: }

测试按预期工作:)

tested and works as expected :)

更多推荐

删除GET变量和.PHP使用htaccess的

本文发布于:2023-11-01 17:49:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550000.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   PHP   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!