重写GET变量php [英] Rewrite GET variables php
问题描述
我想重写,我的脚本是这样的:
I want to make a rewrite,and my script is like this :
<?php
$id = $_GET['id'];
if($id) {
echo "Your id are $id";
} else {
echo "Id are missing";
}
?>
用.htaccess
我想这样在我的网址中:http://example.com/something/id
with .htaccess
i want to make it in my url like this : http://example.com/something/id
那么,我必须在php
中的edit
并添加到我的.htaccess
中吗?
So,what must i edit
in my php
and add to my .htaccess
?
推荐答案
您可以通过此方法自动获取变量值
you can get the variable values automaticly by this method
RewriteEngine On
RewriteBase /
RewriteEngine On Options All -Indexes RewriteBase /directoryname/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
############### SEO ##########################
#
http://www.example.com/hello/booboo/ it takes the url after .com/
RewriteRule ^(.*)$ getme.php?url=$1 [QSA,L]
例如,如果我输入 http://www.example.com/hello/bobo/
它现在将替换为"/hello/bobo/"部分,您可以在.htacces文件中使用它.此外,如果您想重定向到另一页并过滤变量值,则应该修改$ 1,因为其中的所有数据
it is going to replace and take "/hello/bobo/" part now you can use this in .htacces file Also if you want to redirect to another page and filter the variable value you should modify $1 because all data in this.
在该示例中,我在域之后获取网址,并重定向到get.php,您也可以使用split方法将网址除以"/",让我们看一下get.php页面以了解此方法
edit: in that example i get url after my domain and i redirect to get.php also you can divide the url using split method by "/" Let's see the get.php page to understand this method
getme.php:
getme.php:
<?php
//we redirect to get in url=$1 so our get method name is url
$parca = explode("/", $_GET["url"]); //and we divided by slash the url.
echo $parca[0];//this is first part "/hello/
echo $parca[1];// and this is second part "/booboo/;
?>
这篇关于重写GET变量php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!