mod rewrites and $_GET[] strings [SOLVED]

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

mod rewrites and $_GET[] strings [SOLVED]

Post by s.dot »

I have a simple mod rewrite that rewrites domain.com/username to domain.com/user-view.php?user=username.

The problem comes when I want to append information to that url.. ie

domain.com/username?success=1&album_created=12345

Say I wanted to get the value of $_GET['success'] or $_GET['album_created'] ..

They don't appear in the $_GET array.

Do I have to make a rewrite rule like this?

Code: Select all

RewriteRule ^([\w]{3,25})(.+)$ /user-view.php?user=$1&query_string=$2
Then use php to break apart the $_GET['query_string']?

Is there any easier way?

[edit] I don't want to use user-view.php?user=username&success=1&album_created=12345. I want it in the form of domain.com/username?query=string
Last edited by s.dot on Tue Feb 27, 2007 8:53 am, edited 1 time in total.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post by fastfingertips »

There are two ways to make this:

- First you may use the Apache mod-rewrite, if so indeed you will have to add such line. This can be saved in a htaccess file if you are allowed.
- Otherwise as i remember you can make this in php with redirect to 404 or something like that.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

well, to make things a little bit clearer

i would like to be able to use the following

domain.com/username
domain.com/username?some=query&string=foo

With using the mod rewrite to allow the first one, the only thing that gets passed via $_GET is $_GET['user']. How do I make a query string appended to that (such as the second example) available to PHP?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post by Nathaniel »

Untested, but try:

Code: Select all

RewriteRule ^([\w]{3,25}) /user-view.php?user=$1&%{QUERY_STRING}
Note the missing $ after the regex.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Thank you.

With that, the values are passed via $_GET

Code: Select all

Array
(
    [user] => scrotaye
    [success] => sub-album-created
)
However, regular pages like index.php and faq.php trigger the rewrite rule (resulting in "sorry, user index.php does not exist" as it's passing "index.php" to view-user.php?user=index.php)

The exact rewrite rule is..

Code: Select all

RewriteRule ^([\w]{3,25})(/)? view-user.php?user=$1&%{QUERY_STRING}
[edit] HOWEVER, if I add the $ to the end of the regex, it works perfectly. Kinda ironic that's what you pointed out not to put in :lol:

But thanks man!
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply