Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess RewriteRule to work with hidden and visible GETs

Here what I've already done.

RewriteRule ^([a-z]+)$ index.php?file=$1

So when visiting domain.com/browse it actually reads domain.com/index.php?file=browse

But the problem is, this does not pass visible GET variables like this: domain.com/browse?page=2. How do I make it pass both GET variables: domain.com/index.php?file=browse&page=2.

Any help would be appreciated!

like image 525
Prasad N Avatar asked Dec 03 '22 05:12

Prasad N


2 Answers

You can use this:

RewriteRule ^browse/?$ index.php?file=browse&page=1 [L,NC,QSA]
RewriteRule ^browse/([0-9]+)/?$ index.php?file=browse&page=$1 [L,NC,QSA]

#else it's for files
RewriteRule ^([a-z]+)/?$ index.php?file=$1 [L,NC,QSA]

or use:

RewriteRule ^([a-z]+)$ php.php?file=$1 [L,NC,QSA]

the QSA (Query String Append) flag will allow passing _GET vars

like image 184
Book Of Zeus Avatar answered Dec 25 '22 08:12

Book Of Zeus


You must add the query string explicitly in your rewrite:

RewriteRule ^([a-z]+)$ index.php?file=$1&%{QUERY_STRING}
like image 32
Tchoupi Avatar answered Dec 25 '22 07:12

Tchoupi