Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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_Apache_.htaccess_Url_Seo - Fatal编程技术网

Php .htaccess使URL对搜索引擎友好

Php .htaccess使URL对搜索引擎友好,php,apache,.htaccess,url,seo,Php,Apache,.htaccess,Url,Seo,我一直在寻找解决我问题的方法,我发现了这个。但这不符合我的问题。我目前正在使用PHP构建一个网站,并在url中使用了查询字符串。例如,我有很多这样的URL: www.example.com?page=something and also www.example.com?page=something&action=anything 我只想要: www.example.com/something and www.example.com/something/anything 我也不熟悉.h

我一直在寻找解决我问题的方法,我发现了这个。但这不符合我的问题。我目前正在使用PHP构建一个网站,并在url中使用了查询字符串。例如,我有很多这样的URL:

www.example.com?page=something
and also
www.example.com?page=something&action=anything
我只想要:

www.example.com/something
and
www.example.com/something/anything
我也不熟悉.htacess脚本,所以我不知道脚本对我意味着什么,即使我从谷歌那里得到了一些建议


谢谢。

这有不同类型的体系结构

最常见的是
mod_rewrite
。使用一组
重写规则
,您可以随意重定向流量

这方面的一个例子是:

RewriteEngine On
RewriteBase /

RewriteRule ^([^/]+)(?:/([^/]+))? index.php?page=$1&action=$2 [L]
然而,这些规则的管理可能会变得复杂。在您的情况下,您必须为URL创建另一个规则,如:
/some/other/page

另一种方法是使用。您的所有流量都通过一个要路由的位置(如index.php)进行过滤。如果您运行的是Apache2.2.17或更高版本(现在大多数服务器都是这样),那么您可以使用以下命令在一行中完成此操作

例如:

FallbackResource /index.php

这是一个相当初级的重写,带有mod_rewrite。像这样的东西应该可以完成这项工作:

RewriteEngine On
RewriteRule ^([^/]+)(?:/([^/]+))? index.php?page=$1&action=$2 [L]

表达式
([^/])
表示将所有内容匹配到下一个
/
(?:/([^/]+)?
包含相同的模式,但被非捕获组
(?:/)?
包围,这使得整个第二组都是可选的。

使用它时,我看到我的站点不再具有样式或效果。当我查看源代码时,我点击CSS源链接,我被重定向到同一个地方,我在firebug中也看到了这一点。是的,
RewriteRule
将接收所有流量。这可能就是问题所在。我建议改用
FallbackResource