Sushant Panigrahi
Sushant Panigrahi

Reputation: 305

How can I use friendly/rewritten urls in php?

I have problem to encrypt the url.

example

existing url= www.domainname/search.php?key=books&type=title&Submit=search

i want to encrypt this url.

encrypt url= www.domainname/keword-keyword-keyword.html

in this form...

can any one solve my problem.. i will be greatfull to him or her

Upvotes: 0

Views: 185

Answers (3)

Sjoerd
Sjoerd

Reputation: 75599

It is also possible to use a PHP file as common part of the path and parse the request URI yourself. E.g.

http://www.example.com/index.php/books/AliceInWonderland

In this case, index.php could parse the $_SERVER['REQUEST_URI'].

Upvotes: 1

Fenton
Fenton

Reputation: 250922

If you're using PHP, you may well be on an Apache server - in which case you can use Apache's mod_rewrite to provide restful URIs to your visitors.

Here is a short example:

RewriteEngine on
RewriteRule ^Search/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ search.php?key=$1&type=$2&term=$3 [L,NC]

This would translate

http://www.domainname/Search/books/title/Mission%20Impossible/

Into

http://www.domainname/search.php?key=books&type=title&term=Mission%20Impossible

The [L] means no further rules would be evaluated The [NC] makes this case-insensitive (so "Search" and "search" would both work)

Upvotes: 4

Related Questions