I was passing the query to my search results page with variable: ?s=.
I was testing the site and I discovered than when the query has a & symbol in it, when I try to retrieve $_GET['s'] it gets cut in the & symbol.
I tried with & and also converting it to %26 and I’m still having the same problem.
How can I encode them to pass them in URL?
EDIT:
I pointed that I tried encoding it to %26 and it still didn’t work.
I tried with urlencode() and on ?s=pizza%26pasta when I print_r($_GET) I get:
Array ( [s] => pizza [pasta] => )
EDIT 2:
I just found out that the problem actually has to do with .htaccess it seems to transform the ‘&something’ in ‘&something=’. No idea how to fix it in htaccess.
This is my .htaccess file:
RewriteEngine On
RewriteBase /
# remove www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
# rewrite to action
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)/?$ /a/?s=$1 [L,QSA]
Url encoding the amersand (&) to
%26is the correct way to do this.Using
http://yoursite.com?var1=this%26that&var2=otherwill result in your$_GETsuperglobal array having two variablesYou can use the function
urlencodeto automatically encode all characters that require encoding. These are typically the characters that are used to make up the component parts of a url. i.e. the At symbol (@), colon (:), question mark (?), etc.