Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
重写获取变量php_Php_.htaccess_Mod Rewrite - Fatal编程技术网

重写获取变量php

重写获取变量php,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,我想重写,我的脚本是这样的: <?php $id = $_GET['id']; if($id) { echo "Your id are $id"; } else { echo "Id are missing"; } ?> 使用.htaccess,我希望在我的url中这样做:http://example.com/something/id 那么,我必须在php中编辑什么并添加到我的.htaccess中呢?在Root/.htaccess中尝试以下操作 RewriteEngine On

我想重写,我的脚本是这样的:

<?php
$id = $_GET['id'];
if($id) {
echo "Your id are $id";
} else {
echo "Id are missing";
}
?>
使用.htaccess,我希望在我的url中这样做:http://example.com/something/id


那么,我必须在php中编辑什么并添加到我的.htaccess中呢?

在Root/.htaccess中尝试以下操作

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /file.php?id=$1 [NC,L]
用您的文件替换/file.php

这将在内部重定向

example.com/123


在Root/.htaccess中尝试以下操作

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /file.php?id=$1 [NC,L]
用您的文件替换/file.php

这将在内部重定向

example.com/123


通过这种方法,您可以自动获取变量值

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]
例如,如果我进入

它将替换并接受/hello/bobo/part。如果您想重定向到另一个页面并过滤变量值,您也可以在.htacces文件中使用它,您应该修改$1,因为此文件中的所有数据

编辑:在那个例子中,我在我的域之后获取url,并重定向到get.php。您也可以使用split方法将url除以/get.php页面来理解这个方法

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]
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/;
?>

通过这种方法,您可以自动获取变量值

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]
例如,如果我进入

它将替换并接受/hello/bobo/part。如果您想重定向到另一个页面并过滤变量值,您也可以在.htacces文件中使用它,您应该修改$1,因为此文件中的所有数据

编辑:在那个例子中,我在我的域之后获取url,并重定向到get.php。您也可以使用split方法将url除以/get.php页面来理解这个方法

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]
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/;
?>

如果我的文件是/something/index.php file.php替换为index.php?如果目标路径是/something/index.php,那么你可以用/something/index.phpso替换file.php,如果我的文件是/something/index.php file.php替换为index.php?如果目标路径是/something/index.php,然后你可以用/something/index.php替换file.php谢谢:我明白了