Forum Moderators: phranque

Message Too Old, No Replies

Passing (advanced) $ GET with mod rewrite

         

mightylobster

11:36 pm on Feb 13, 2009 (gmt 0)

10+ Year Member



I guess a quick rundown of what I'm trying to achieve would be in order. Basically, whenever an user attempts to access a file on the domain, access.php will check whether he or her is authorized to view it, and then either include it (.php-files) or simply print the file out with the correct header.

I was able to achieve that with:

RewriteCond $1 !^(access\.php)

RewriteRule ^(.*)$ access.php?page=$1 [L]

However, passing $_GET values to .php pages is impossible with this, and that is what I need your help with.

I'm pretty new to mod_rewrite, and regular expressions in general, so this has become quite a problem to me. I'm pretty confident that this is possible - I'm just not good enough. Here is my unsuccessful attempt at doing this:

RewriteCond $1 !^(access\.php)

RewriteRule ^(.*^\?)(\?(.*))*$ access.php?page=$1&$3 [L]

To clarify, I'm attempting to turn http://url.com/index.php?test=something to http://url.com/access.php?page=index.php&test=something.

Thanks in advance for any help.

g1smd

12:30 am on Feb 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



*** To clarify, I'm attempting to turn http ://url.com/index.php?test=something to http ://url.com/access.php?page=index.php&test=something. ***

Unfortunately, that clarifies nothing. Rewrites cannot 'turn' something into something else, and your example is for two URLs. When there are two URLs involved, that's usually a redirect. A rewrite translates a URL Request into a Server-Internal Filepath, so the example would not mention two URLs. Additionally, for the URL that you would want users to 'see' and 'use' you would need to use that exact URL in the links within your site.

Take note of the notes in this thread... [webmasterworld.com...] especially post #3846403 and #3846577 there.

[edited by: g1smd at 12:39 am (utc) on Feb. 14, 2009]

jdMorgan

12:35 am on Feb 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteCond $1 !^access\.php$
RewriteRule (.*) access.php?page=$1 [QSA,L]

Jim

mightylobster

1:33 am on Feb 14, 2009 (gmt 0)

10+ Year Member



That was exactly what I was looking for.

Thanks a bunch.