2

I'm trying to turn http://www.placeholder.com/lala.php?fname=bob into http://placeholder.com/lala/bob

      <form action="lala.php" method="get">
    Name: <input type="text" name="fname">
    <input type="submit">
    </form> 
Welcome <?php echo $_GET["fname"]; ?>.<br>

I tried this on the .htaccess, but nothing happened

Redirect 302 /lala.php?fname=bob http://www.placeholder.com/lala/bob.php

Is this possible?

1
  • 2
    Just to clarify, which URL do you want the user to see in their browser? Commented Aug 9, 2013 at 1:09

3 Answers 3

1

If you want to send visitors from http://www.starsqa.com/lala/bob to http://www.starsqa.com/lala.php?fname=bob:

 RewriteCond %{QUERY_STRING} ^$
 RewriteRule ^/lala/bob$ /lala.php?fname=bob [L,QSA]
 RewriteCond %{QUERY_STRING} ^$
 RewriteRule ^/lala/bob/$ /lala.php?fname=bob [L]

If you want a general pattern where fname can be any name, try this:

 RewriteCond %{QUERY_STRING} ^$
 RewriteRule ^/lala/([a-zA-Z0-9:\@.\-\+]{1,100})$ /lala.php?fname=$1 [L,QSA]
 RewriteCond %{QUERY_STRING} ^$
 RewriteRule ^/lala/([a-zA-Z0-9:\@.\-\+]{1,100})/$ /lala.php?fname=$1 [L]

If instead you want to send visitors from http://www.starsqa.com/lala.php?fname=bob to http://www.starsqa.com/lala/bob :

 RewriteCond %{QUERY_STRING} ^$
 RewriteRule ^/lala.php?fname=bob$ /lala/bob [L]

And similarly, a more general pattern for this would be:

 RewriteCond %{QUERY_STRING} ^$
 RewriteRule ^/lala.php?fname=([a-zA-Z0-9:\@.\-\+]{1,100})$ /lala.php/$1 [L]

Last Example (sending a user from starsQA.com/jen-lilley-contact to starsQA.com/contact-id=6) :

 RewriteCond %{QUERY_STRING} ^$
 RewriteRule ^/jen-lilley-contact$ /contact-id=6 [L]

By the way, do not forget to restart Apache.

How to restart Apache depends on your platform configuration. What OS are you running it on?

Sign up to request clarification or add additional context in comments.

4 Comments

What I have written as the answer will work if a user were to type starsqa.com/lala/bob but instead you want to redirect the request to starsqa.com/lala.php?fname=bob. Are you saying you want the reverse of that? That is, you want the users to type starsqa.com/lala.php?fname=bob instead?
i can add it under this stuff right? Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ $1.php [L,QSA]
how do i reset apache on a live site?
os = windows and the site is live and not on a visual server like xampp
0

You need to look into mod_rewrite, see example and explanation here: http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/

Something like

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/lala\.php$
RewriteCond %{QUERY_STRING} ^fname=bob$
RewriteRule ^(.*)$ http://www.starsQA.com/lala/bob.php [R=302,QSD,L]

3 Comments

made no change to the url sadly
Yea, that is the part that you want
0
RewriteRule ^/lala/(.*)$ /lala.php?fname=$1 [R=302,L]

opposite?

RewriteRule ^/lala.php?fname=(.*)$ /lala/$1.php [R=302,L]

Comments

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.