当用户访问www.mysite.com/string时,它是否可以重定向到我的索引并使用该字符串?

Currently I have it setup like this so when a user visits www.mysite.com/test.php?u=String the user string will be set as String.

$user = $_GET['u'];

But is it possible to have it if a user searches www.mysite.com/String it would set the user value as the string.

$user

I’m guessing it would require me to edit the .htmlaccess file but I am unsure on how I would do this.

Thankyou in advance

It's .htaccess not .htmlaccess

If you want to keep the URL as something like: http://www.example.com/search but, in reality, direct to http://www.example.com/test.php?u=search then you'll probably want a RewriteRule

In this instance, to route everything that's neither a file nor a directory to test.php?u=string

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /test.php?u=$1 [NC,L,QSA]

http://www.example.com/this/is/not/a/directory will be routed to http://www.example.com/test/php?u=this/is/not/a/directory

This needs to be in an .htaccess file at your document root.

You could make a .htaccess redirect for all requests, and route them to your test.php file, which then assigns the string to your $user variable.

The script would look something like this

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /test.php?u=$1 [NC,L,QSA]

I hope you're also considering the security risks of letting a user input any string they want in your script just by visiting mysite.com/String