-1

Im trying to get pretty urls but i don't know anything about htaccess.

trying to get something like
this:

domain.com/?page=login
domain.com/?page=user&uid=2

to:

domain.com/login/
domain.com/user/2

do i have to specify everything like this?:

domain.com/Page?a=arg1&b=arg2&c=arg3
domain.com/Page/arg1/arg2/arg3

or can it be "more dynamic"?

objectnabb
  • 93
  • 2
  • 9
  • 1
    Give a look at: http://stackoverflow.com/questions/812571/how-to-create-friendly-url-in-php – gvsrepins May 09 '13 at 18:23
  • 1
    So are you planning on trying to learn how to use mod_rewrite? have you tried to use it and are having problems? Or are you just wanting us to tell you how to do it? Not to mention there are probably thousands of questions on SO and lots of resources available on the internet about how to do this. – Mike Brant May 09 '13 at 18:24
  • [Here](http://stackoverflow.com/questions/9105940/user-friendly-urls-mod-rewrite-and-php-redirections/16401451#16401451) is my solution in similar thread. – Danijel May 09 '13 at 18:24
  • I think you have it backwards, you should be redirecting domain.com/login/ to be domain.com/?page=login in your htaccess. – Decker W Brower May 09 '13 at 18:27
  • Mike Brant , Both actually :) – objectnabb May 09 '13 at 18:29
  • If you need this a lot you'll want to look into *routing*. E.g. http://github.com/deceze/Kunststube-Router – deceze May 09 '13 at 18:43
  • thx deceze, this looks promising – objectnabb May 09 '13 at 18:56

2 Answers2

0

I like using http://www.generateit.net/mod-rewrite/ . Pretty easy to figure out how it's done when you used that tool 2 or 3 times.

You can define which parameters take which "spot"

so to get your:

domain.com/?page=login
domain.com/?page=user&uid=2

to:

domain.com/login/
domain.com/user/2

You can use:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /?page=$1&uid=$2 [L]

Your "page" problem looks a bit more difficult.

You would have to add rewrite rules for each "page" or file I guess.

At least I don't know how to do that.

If it's a folder you could solve that by giving the folder its own .htaccess

Edit:

RewriteEngine On
RewriteRule ^Page/([^/]*)/([^/]*)/([^/]*)\.html$ /Page.php?a=$1&b=$2&c=$3 [L]

Might work. I added Page/ under prefix in the generator

Community
  • 1
  • 1
Wurstbro
  • 974
  • 1
  • 9
  • 21
0

If this is a new project I suggest using a framework such as Zend Framework. Their built-in default routing accepts url's in the fashion that you want.

For Example a request for a user login page with a user id of 123 can look like this: /user/login/id/123

Read more here: http://framework.zend.com/manual/2.1/en/user-guide/routing-and-controllers.html

There are other frameworks like Cake or Code Ignitor that can do the same thing. However, I believe they (and Zend) do require mod_rewrite to be installed on apache.

atorres757
  • 601
  • 5
  • 9
  • Yes its a new project, but since its for learning purposes i'm trying to build my own template "like system" and getting myself comfortable with the diffrent languages and how things are built from scratch. I hope this makes sense :) – objectnabb May 09 '13 at 18:44