PHP读取URL进行搜索(Apache)


PHP read the URL for search (Apache)

我需要在中

url: domain.com/search/hola

忽略这个hola(所以转到/search/index.php),但在php变量中有这个hola

例如,我在浏览器中键入domain.com/search/google,然后转到domain.com/search/index.php,代码为:

$search = $_GET['url']; //(obviously, this doesn't works)<br>
print_r($url);

类似的事情:http://example.com/把你放的东西放到同一个网站上。

您可以使用RewriteRule执行此操作。

将模块mod_rewrite安装到Apache中。根据您的服务器和操作系统,说明可能有所不同,但大多数情况下它已经安装好了。

检查Apache的站点配置中是否指定了AllowOverride All以允许.htaccess文件。

在Web服务器的根文件夹中创建一个.htaccess文件。

RewriteEngine On
RewriteRule    ^/search/(.*)    /search/index.php?param=$1    [L,QSA]

如果您对apache配置进行任何更改或安装新模块,则必须重新启动apache服务。.htaccess文件中的更改不需要重新启动。

  • HowTohttp://httpd.apache.org/docs/current/mod/mod_rewrite.html