Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

My mod rewrite rule mysteriously cuts off the periods from my query string.

For example, this is the request url:

http://mysite/tag/2/Search+For+Articles...

this is the query string I want:

tag=2&clear=Search+For+Articles...

but this is what I get

tag=2&clear=Search+For+Articles

Here is my mod_rewrite configuration

Options -Indexes
Options +FollowSymLinks
RewriteEngine On

RewriteRule ^tag/([^/]*)/([^/]*)(/?)$ f.php?tag=$1&clear=$2 [L,QSA]

How can I fix this problem?

share|improve this question
    
Could you please give us the exactly apart after the Search+For+Articles? I also suggest you enabling RewriteLog and setting RewriteLoglevel to see what the log says. –  quanta Aug 21 '11 at 5:00

1 Answer 1

I think the problem may be with your Apache configuration itself... I created a simple f.php script on one of my Apache2 servers that simply consisted of the following:

<pre>
<?php
print_r($_SERVER);
?>
</pre>

I then created the .htaccess file with the exact contents you specified in your question. Now when I hit http://my.server.com/tag/2/Search+For+Articles... I got a 404 error. However if I called it as http://my.server.com/f.php?tag=2&clear=Search+For+Articles... I got the output I expected. I then went back to my Apache config and found that the Directory listing for the path I was working in had AllowOverride None so I changed it to AllowOverride All and attempted the /tag/... prefixed URI and low and behold I received the following output:

Array
(
    [REDIRECT_STATUS] => 200
    [HTTP_HOST] => my.server.com
    [PATH] => /usr/local/bin:/usr/bin:/bin
    [DOCUMENT_ROOT] => /var/www
    [SERVER_ADMIN] => webmaster@localhost
    [SCRIPT_FILENAME] => /var/www/f.php
    [REMOTE_PORT] => 35393
    [REDIRECT_QUERY_STRING] => tag=2&clear=Search+For+Articles...
    [REDIRECT_URL] => /tag/2/Search+For+Articles...
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] => tag=2&clear=Search+For+Articles...
    [REQUEST_URI] => /tag/2/Search+For+Articles...
    [SCRIPT_NAME] => /f.php
    [PHP_SELF] => /f.php
    [REQUEST_TIME] => 1313889895
)

I've cleaned up some of the variables specific to my server but as you can see the QUERY_STRING is as expected.

share|improve this answer
    
This is good info but I still can't get it to work it seems to always drop the ... –  needHELP Aug 21 '11 at 3:16
    
What is your server environment? I did this on an Ubuntu Server 11.04 with Apache 2.2.17. Aside from the AllowOverride change I didn't touch anything within the existing default Apache server config. The .htaccess was what you had put forth. –  Jeremy Bouse Aug 21 '11 at 14:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.