views:

19

answers:

2

so i read stuff about how apache's mod_rewrite does the trick but it seems to be too vague for beginners like me.

lets say i wanted to mask site.com/userpage.php into site.com/ or site.com/userpage

or even removing the get requests..

from site.com/userpage.php?query=yes into site.com/userpage.php or site.com/userpage

how can i do that by using htaccess or even other methods?

thanks guys

A: 

If you don't want to append the GET requests, why not use POST?

Also, you can use MultiViews to allow /userpage.php to be accessed as /userpage.

Options Indexes FollowSymLinks Includes MultiViews

The way MultiViews works it will check for a directory named userpage, and if it finds none, then it will go to the file, just a heads up in case you had a directory named userpage as well.

Robert
A: 

First, remember to put this line in your .htaccess before any rewrites:

RewriteEngine on

If you want site.com/something to display site.com/something.php if it exists without changing the URL, do this:

RewriteCond %{REQUEST_URI}.php -f
RewriteRule .* %{REQUEST_URI}.php

That will display a [file you requested].php if it exists while still showing the same URL you entered. If the php file doesn't exist, it will still give you a 404 as it should. (That's what the -f is for.)

There is no way to hide the GET requests completely. You can get rid of the GET requests, but then they won't be available to your script either and there's no point. You can, however, make it look nicer. For example, if you want site.com/userpage/item/30 to display the content of site.com/userpage.php?item=30, you can do something like this:

RewriteRule ^/userpage/item/(.*)$ userpage.php?item=$1

You could also make it work with any GET value with a rule like this:

RewriteRule ^/userpage/(.*)/(.*)$ userpage.php?$1=$2

With that in effect, you could access site.com/userpage.php?query=yes with site.com/userpage/query/yes instead. That's pretty much the best you can do; GET values have to come from the URL somehow, so if you want your inputs completely hidden you'll have to use POST instead.

qmega