Forum Moderators: phranque

Message Too Old, No Replies

can't access other $ GET variables by this rule

         

force123

7:17 am on Mar 13, 2009 (gmt 0)

10+ Year Member



Hi,

I've wrote this :

RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteCond %{REQUEST_URI} !^/forums/([^.]+)?$
RewriteRule ^(.+)/(.+)/$ index.php?act1=$1&act2=$2 [L]

to solve this :

http://www.example.com/action1/action2/

and it works fine.
But when I try this url :

http://www.example.com/action1/action2/?test=yes

It doesn't give me the $_GET['test'].

How can I fix that ?

Caterham

8:41 am on Mar 13, 2009 (gmt 0)

10+ Year Member



How can I fix that ?

Add the QSA flag. The manual hast more details about it.

force123

8:47 am on Mar 13, 2009 (gmt 0)

10+ Year Member



Nice. Thanks

Another thing,
I can't access the pages by this :

http://www.example.com/action1/action2

because it doesn't end with that / . How can I tune it so that I don't cause a duplicate page?

jdMorgan

5:37 pm on Mar 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add another rule to detect the missing trailing slash on URL-paths that do not resolve to existing files, and invoke a 301 redirect to add that slash. See the "-f" flag for RewriteCond.

Your RewriteRule pattern can be improved for efficiency and specificity. Try:


RewriteRule ^([^/]+)/([^/]+)/$ index.php?act1=$1&act2=$2 [QSA,L]

Jim

g1smd

8:29 pm on Mar 13, 2009 (gmt 0)

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



Make sure you place your new redirect before the rewrite.

The new redirect must contain the domain in the target URL, and end with [R=301,L].

force123

6:37 pm on Mar 15, 2009 (gmt 0)

10+ Year Member



Would this be the perfect line I could set for the redirect :

RewriteRule ^([^/]+)/([^/]+)$ /$1/$2/ [R=301,QSA,L]

?

(I put QSA to catch other get variables)

jdMorgan

7:24 pm on Mar 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[QSA] is not needed unless you wish to *append* new query string data to the existing query string. If no query string data is specified in the RewriteRule substitution, then by default, mod_rewrite passes the existing query string data through without changing it.

You will have to decide if the pattern you show here is sufficient. it will accept a URL-path of /<anything-but-a-slash>/<anything-but-a-slash>. So, yes, this will redirect a request for "/foo/bar" to "/foo/bar/".

But it will also redirect a request for "/images/logo.gif" to "/images/logo.gif/" which is not likely what you would want. Generally, I would recommend at least a slightly-more-restrictive pattern of


RewriteRule ^([^/]+)/([b][^/.][/b]+)$ http://www.example.com/$1/$2/ [R=301,L]

Note also that the full protocol and domain should usually be specified when doing a redirect, as shown here.

Jim