Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.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 如何创建良好的htaccess_Php_.htaccess_Web - Fatal编程技术网

Php 如何创建良好的htaccess

Php 如何创建良好的htaccess,php,.htaccess,web,Php,.htaccess,Web,对不起,我刚开始学习.htaccess文件。我正试图这样写(我的htaccess文件) 重新启动发动机 重写BASE/exmpl/vadik_路由/ 重写cond%{REQUEST_FILENAME}-F 重写cond%{REQUEST_FILENAME}-D ReqriteRule^(.*)$index.php/$l 您可以通过get方法发送url,例如getme.php?url=/controller/model/ 你也可以把url除以斜杠 $_GET['url'] //it is g

对不起,我刚开始学习.htaccess文件。我正试图这样写(我的htaccess文件)


重新启动发动机
重写BASE/exmpl/vadik_路由/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
ReqriteRule^(.*)$index.php/$l

您可以通过get方法发送url,例如getme.php?url=/controller/model/ 你也可以把url除以斜杠

 $_GET['url'] //it is going to show you the url.
让我们看看.htaccess并解释它

    RewriteEngine On
    RewriteBase / #dont forget to modify this part. it is explain which folder you project in
    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]
现在我们将所有url发送到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 the url by slash .

echo $parca[0];//this is first part "/hello/
echo $parca[1];// and this is second part "/booboo/;
?>

使用此选项更改您的.htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L]

$l应为$1,且其重写不需要重新写入。服务器错误日志?例如,debian上的
/var/log/apache2/error.log
。另外,apache主配置是否有
AllowOverride
?您的htaccess充满了syntex错误。感谢您的详细回答。尤其是@AhmetAtak,你的例子非常清楚。萨戈尔加德斯!我已经创建了.htaccess和index.php文件,在那里我可以为我的文件夹设置清晰的路径,但是我有一个文件夹登录,其中包含了我的所有登录文件和语言设置文件。当我选择其中一种语言时,它是这样的“form.php?lang=kr”。我无法在main index.php文件中为它们编写路径,所以我是否也应该为它们创建htaccess文件?我的目标是创建具有清晰url的网页。如果可能,请告诉我?事实上,如果您在index.php中编写echo$_GET[“url”],您将看到类似于“form.php?lang=kr”的内容,但是我们用斜线分隔地址,您知道www.example.com/hello/boobooboo/它意味着$parca[0]=hello,$parca[1]=booboo所以你可以写www.example.com/language/kr/第一个是语言,第二个是kr,你可以说如果($parca[1]='kr')包含“your language file.php”,如果你不想使用它,你应该在这个RewriteRule^(.*)$getme.php?url=$1[QSA,L]”之前添加“RewriteRule^form.php?lang=(.*)$getme.php?url=$1[QSA,L]当你把这个放进去时,你会发现url将是url=kr