trailing ? in a rewrite rule appends query string

Oh, the strange things mod_rewrite does!

trailing ? in a rewrite rule appends query string

Postby longears » Mon Oct 29, 2007 1:43 pm

Here's my current rule:

Code: Select all
RewriteRule ^admin/?$ index.php?page=admin [L]


When I go to http://domain.com/admin/ everything works just fine. When I go to http://domain.com/admin the correct page is shown, but the address in the browser changes to http://domain.com/admin?page=admin

I would rather the browser address not change. Is there an easy fix?

Thanks!!
longears
 
Posts: 12
Joined: Fri Jul 27, 2007 1:39 pm

Postby richardk » Tue Oct 30, 2007 9:52 am

Does the /admin directory exist? If yes, then use
Code: Select all
RewriteRule ^admin$   /admin/         [R=301,L]
RewriteRule ^admin/?$ /index.php?page=admin [L]


Or do you have other rules? If you do, post them.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby yui » Sat Nov 03, 2007 7:04 am

I have the same problem, but the rule you posted didn't fix it. Additionally I would prefer a rule, which works in any case no matter whether or not the folder exists.

Why is the address in the clients browser changed in this case anyway? I thought the redirection of the request of this rule would only be made internally in the server.
yui
 
Posts: 2
Joined: Sat Nov 03, 2007 6:58 am

Postby richardk » Sun Nov 04, 2007 8:27 am

You can try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [r=301,L]

# current rules

Or you'll need to post your mod_rewrite.

Why is the address in the clients browser changed in this case anyway? I thought the redirection of the request of this rule would only be made internally in the server.

Redirects change the browser's address bar vs. rewrites which are internal. It has to be a redirect because it's a conflict with another module (mod_dir, which adds missing trailing slashes).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby yui » Sun Nov 04, 2007 12:44 pm

Thank you, richardk!
yui
 
Posts: 2
Joined: Sat Nov 03, 2007 6:58 am


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 18 guests

cron