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 protected]

I want to display the above url like this,

http://localhost/info/john/zend/[email protected]

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.

6
  • 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. Commented Sep 17, 2014 at 12:21
  • 1
    possible duplicate of Clean URLs for search query? Commented Sep 17, 2014 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 Commented Sep 17, 2014 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). Commented Sep 17, 2014 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: laravel.com/docs/routing#route-parameters Commented Sep 17, 2014 at 14:34

2 Answers 2

1

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]
Sign up to request clarification or add additional context in comments.

1 Comment

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.
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]

1 Comment

This does the opposite of what is wanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.