Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.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重写URL_Php_.htaccess_Mod Rewrite - Fatal编程技术网

Php 通过.htaccess重写URL

Php 通过.htaccess重写URL,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,我有3个URL,我想重写: `health.php?news=apple` to `/health/news/apple` health.php?info=apple至/health/info/apple health.php?articles=apple至/health/articles/apple 为此,我编写了以下给定代码: RewriteRule ^health health.php RewriteRule health/news/(.*) /health.php?news=$1 [N

我有3个URL,我想重写:

`health.php?news=apple` to `/health/news/apple`
health.php?info=apple
/health/info/apple

health.php?articles=apple
/health/articles/apple

为此,我编写了以下给定代码:

RewriteRule ^health health.php
RewriteRule health/news/(.*) /health.php?news=$1 [NC,QSA]
RewriteRule health/info/(.*) /health.php?info=$1 [NC,QSA]
RewriteRule health/articles/(.*) /health.php?articles=$1 [NC,QSA]
但这不起作用。 请帮帮我

提前谢谢

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^health/(.*)/(.*) health.php?$1=$2 

上面的代码将重定向到health页面,然后使用第一个变量作为get变量键,第二个变量作为值

您的第一条规则将重定向任何以运行状况开头的规则,您的其他3条规则将永远不匹配,因为RewriteRule不以斜杠开头。抱歉,这是我写的错误…您想在访问PHP页面或访问漂亮URL时重定向吗?你有多重访问权限吗?你的文件夹结构是什么?我有wordpress网站。在根目录中,我创建了htaccess文件并创建了health.php。基本上health.php是我网站的搜索页面。它为3个标题创建了3个链接:我想打开并运行url,如:@RahulGupta如果你正在使用wordpress为什么不尝试使用wordpress permalink?嗨,Harikrish,在将此代码放到.htaccess文件页(第404页)后,感谢你的评论:(@RahulGupta health拼写不正确,我已经更正了它,您现在可以尝试使用以下代码吗:RewriteRule^health/(.*)/(.*)health.php?$1=$2 RewriteRule^health.phpHi Harikrish….再次帮助我…我如何重定向:()到()RewriteRule^health/search/(.*)/(.*)health.php?$1=$2