victor7cap
victor7cap

Reputation: 13

PHP read the URL for search (Apache)

I need in the

url: domain.com/search/hola

to ignore this hola (so go to /search/index.php) but have this hola in a php variable.

For example i type domain.com/search/google in my browser, then go to domain.com/search/index.php with the code:

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

Something like that: http://example.com/ put what you put go to the same site.

Upvotes: 0

Views: 67

Answers (1)

ToBe
ToBe

Reputation: 2681

You can do this with a RewriteRule.

Install the module mod_rewrite into your Apache. Depending on your server and OS, instructions may differ, but most of the time it's already installed.

Check that AllowOverride All is specified in your Apache's site configuration to allow .htaccess files.

Create a .htaccess file in the root folder of your webserver.

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

If you do any changes in your apache configuration or install a new module, you will have to restart the apache service. Changes in a .htaccess file do not require a restart.

Upvotes: 1

Related Questions