Question

I have a website that passes some GET variables to different pages in PHP. My issue is that now I have a url with variables i.e. index.php?category=categoryname and that's not very memorable.

Is there any way I can change the URL to something like /categoryname instead without duplicating the page and storing in folders? But also allow users to type in /categoryname and be redirected to the correct page?

Was it helpful?

Solution

.htaccess Apache mod_rewrite, almost every professional dynamic website uses this method (like stackoverflow).

The method is fully explained in this article far better then I could ever explain it in this answer box.

OTHER TIPS

You should look into writing some apache Mod_Rewrite rules in a .htaccess file.

The solution is discussed here:

this is done by the rewrite module of apache and this handles regular expressions. You have to put a rule like this in your .htaccess file on the root of your website:

RewriteRule ^cat/([0-9]+)$ /index.php?category=$1

^ means the start of the url after www.example.com/ $ means the end of the page.

www.example.com/cat/123

will be converted by the server to:

www.example.com/index.php?category=123

In PHP you use the normal $_GET['id'] variable. The rewrite module must be enabled by apache... This is mostly used to make the url format independent of the serverside scripting language so the .php in the url is not logical. Thats why i changed it to product/ . The .htaccess starts with

RewriteEngine On Options +FollowSymLinks RewriteBase / Here all the rewrite rules.. ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top