transparent
transparent

Reputation: 182

Multiple Clean Url Variables

I was wondering how to pass several (two) values through url as a clean url. I've done clean urls before, but never with multiple values and it doesn't seem to be working.

This is what the url looks like now:

http://example.com/?user=Username&page=1

This is what I want it to look like

http://example.com/user/Username/page/1

I've tried other answers that I've seen on here, but they aren't working for this certain deal.

RewriteEngine On
# Don't match real existing files so CSS, scripts, images aren't rewritten
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d

# Match the first two groups before / and send them to the query string
RewriteRule ^([^/]+)/([^/]+) index.php?user=$1&page=$2 [L] 

Thanks. :) I'm using PHP by the way. :)

Also, will I still be able to use $_GET with this? I thought so, but I also somewhere else where it said you can't... :D

Upvotes: 0

Views: 2093

Answers (1)

Jon Lin
Jon Lin

Reputation: 143886

You're missing several matches, try:

RewriteEngine On
# Don't match real existing files so CSS, scripts, images aren't rewritten
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+) index.php?$1=$2&$3=$4 [L] 

This will take a URL like:

http://example.com/a/b/c/d

to the URI:

/index.php?a=b&c=d

will I still be able to use $_GET with this? I thought so, but I also somewhere else where it said you can't.

In the above example, when you look at $_GET['a'] you'd get b.

Upvotes: 3

Related Questions