How to Write A Query String in PHP without a Question Mark
If you are into developing applications in PHP, writing a PHP query string without a question mark is really easy. With a few modifications, you should be able to successfully write nice query strings that are readable and makes sense to both humans and search engines. To achieve this in PHP, a few modifications have to made to the .htaccess file in the root directory that you have placed on your website server. You can use any free PHP editor or IDE to write your PHP code and test the results.
To understand the process of writing a PHP query string without question mark, let us consider that you own a domain called www.example.com. Let the home page contain two text boxes; one for searching the name and one for searching the location. When the submit button is clicked after the appropriate data is entered, the URL returned will look something like
To access the query that comes after the question mark '?' you have to use the $_SERVER['QUERY_STRING'] global array that holds the data that comes after the question mark. To check the data that comes after the question mark, use the echo function that is provided by PHP to display data on the web page.
The echo $_SERVER['QUERY_STRING'] will display name=John&location=california
Our requirement is to have the url look like
To achieve this result create a .htaccess file in the same directory where the page is present (in our case, it is the index.php page that is loaded by default.) In the .htaccess file write the following two lines.
RewriteRule .* index.php
Save and close this file. Refresh or reload the default web page where you enter the query. Write any query and submit the form to see the results. You will see that the query will not have any question marks and you will get the url as desired that is search engine friendly and makes sense to any user.