tags:

views:

78

answers:

5

ok assume i have php page has this name name.php?get= and has get varible named get ok how i can make it appear like that name?get=

+1  A: 

As far as i could understand your question, you can not strip the file extension because otherwise it will not run. In other words, you can not change:

name.php?get=

into

name?get=

But if you mean to create links with query string values that you can put them in hyperlinks in this way:

<a href="name.php?get=whatever">Click here !!</a>
Sarfraz
Depending on the web server, you can absolutely 'strip the file extension', e.g. with mod_rewrite on Apache.
njk
@njk You can, but it's ugly and not the ideal way of doing things. URLs then would become name?get=whatever and not name/?get=whatever.To me, the latter seems much nicer.
Giles Van Gruisen
Anything is possible with mod_rewrite, and in fact "name?get=" is the requirement in the above question...
njk
+6  A: 

If you are using apache, mod_rewrite is one way to go. There is a whole bunch of mod_rewrite tricks here.

Ewan Todd
+1  A: 

If you're looking to create links using a variable '$get', then you can create the link like this:

<a href="name.php?get=$get>Link</a>

Or if you want to get the value of the query string variable, you can use this:

$get = $_GET['get']

Aaron
+3  A: 

I think you're wanting to re-write the URL client-side, which would include mod_rewrite.

In the route of your website, create a file called .htaccess and place the following code in it:

RewriteEngine on
RewriteRule ^name?get=(.*) /name.php?get=$1

Now when you type http://www.example.com/name?get=something, it will actually map to http://www.example.com/name.php?get=something transparently for you.

Martin Bean
+2  A: 

I'd seriously reconsider before using (or overusing) mod_rewrite.

In almost all of my projects I use a simple mod rewrite in the .htaccess:

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^.*$ ./

AddHandler php5-script .php

This tells the server to forward all pages to / (index.php) unless a file otherwise exists.

In the root directory I have a folder called "views" with all of the pages that I use. E.g. the file used for /home would actually be /views/home.php. However, in the index.php I have a script that parses the user's url, checks for the file, and includes that.

$page = substr($_SERVER['REQUEST_URI'], 1);
if(!$page) :
    header("Location: /home");
if(file_exists("views/$page.php")) :
    include "views/$page.php";
else :
    include "views/$page.php";
endif;

This creates a variable called $page that stores the value of everything in the URL after the domain name. I use a substr() function on the Request URI to get rid of the trailing forward slash (/) on the URL.

If the variable is empty, for example if the user is simply at http://example.com or http://example.com/ then it forwards them to /home, where the script then checks for the home.php file inside of the views folder. If that file exists, it includes it, and displays it to the user.

Else, the script will simply include the 404 page telling the user that the file doesn't exist.

Hopefully this helps you, and if you need any further explanation I'd be happy to help!

Giles Van Gruisen