7

I'm developing a website in php and this is my first site using php and I'm new to php.

The site contains 2 pages, index.php and info.php

The index.php has the below form,

<form action="info.php" method="get">
    <input type="text" name="username" />
    <input type="text" name="company" />
    <input type="email" name="email" />
    <button type="submit">Click to Proceed!</button>
</form>

When the user enter and submit the details. It redirects to the next page and the url contains the query string like,

http://localhost/info?username=john&company=zend&email=beast@example.com

I want to display the above url like this,

http://localhost/info/john/zend/beast@example.com

and to get the values from url using $_GET['username'],$_GET['company'] and $_GET['email']

I tried the lot of rewrite rule including the below in htaccess,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteRule ^([\d\w-]+)$ info?username=$1&company=$2&email=$3 [L,QSA]
RewriteRule ^([\d\w-]+)$ info?username=$1&company=$2&email=$3 [QSA]
RewriteRule ^(.*)$ info?username=$1&company=$2&email=$3 [L,QSA]
RewriteRule ^([a-zA-Z0-9-/]+)/([0-9]+)$ info?username=$1&company=$2&email=$3 [L,QSA]
RewriteRule ^([a-zA-Z0-9-/]+)/([0-9]+)$ info?username=$1&company=$2&email=$3 [QSA]

but nothing works.

I tried this and Clean URLs for search query? too.

would somebody help me with this issue.

Community
  • 1
  • 1
Gopinath Perumal
  • 2,258
  • 3
  • 28
  • 41
  • You can't really change this on the serverside, you have to do it with JavaScript. If you want clean URLs you should use POST instead of GET. – Gerald Schneider Sep 17 '14 at 12:21
  • 1
    possible duplicate of [Clean URLs for search query?](http://stackoverflow.com/questions/5464481/clean-urls-for-search-query) – Gerald Schneider Sep 17 '14 at 12:23
  • I don't want clean urls. I need these values in the next page via url only. That's why I'm using GET – Gopinath Perumal Sep 17 '14 at 12:29
  • 1
    @GeraldSchneider You are saying that this can't be done. But many have agreed and ansered that it is working refer the links I have given(recently edited). – Gopinath Perumal Sep 17 '14 at 12:40
  • What you want is called **Routing** and it has been already implemented in many frameworks out there. Just pick one and see how it works. Pick laravel 4 for example, See this covers exactly what you want: http://laravel.com/docs/routing#route-parameters – Yang Sep 17 '14 at 14:34
  • Could you please refer this [link](http://stackoverflow.com/questions/4301481/how-do-i-convert-a-php-query-string-into-a-slash-based-url). Might Give You some idea. – Jansha Sep 18 '14 at 13:05

2 Answers2

2

The flow is this.

submit your form to route.php

here is the code to route.php

if(isset($_GET['username']) && isset($_GET['company'])  && isset($_GET['email']) )
    $url = '/info/'.$_GET['username'].'/'.$_GET['company'].'/'.$_GET['email']
header('Location: '.$url);

In your .htaccess

RewriteRule  ^info/(.+)/(.+)/(.+)$ info.php?username=$1&company=$2&email=$3 [L,QSA]
MontrealDevOne
  • 1,034
  • 3
  • 17
  • 30
  • Thanks for the answer. It does redirect to /info/myname/mycompany/myemail, but it leads to this, /info/myname/mycompany/myemail.php was not found on this server. – Gopinath Perumal Sep 18 '14 at 13:09
0

Check with a simple rule,if rewrite is working. Make sure rewrite module is enabled.

 RewriteRule  ^info/(.+)/(.+)/(.+)(/*)$ info?username=$1&company=$2&email=$3 [L,QSA]
Vicky
  • 603
  • 5
  • 6