0

for this page

www.industrialstores.com/search_results/Bell+%26+Gossett+101238+1.25"+Sweat+ChecktroLFlangeset/46

I am not getting value in $_GET['s']

the value in $_GET['s'] should be Bell Gossett 101238 1.25" Sweat ChecktroLFlangeset but only Bell is passed into $_GET['s']

I already tried urldecode(), htmlentities but not of use.

My .httaccess file is like

RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([a-zA-Z0-9_]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4 [L]
RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4&q=$5 [L]
RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4&q=$5&r=$6 [L]
Aleks G
  • 56,435
  • 29
  • 168
  • 265
  • You shouldn't be getting anything in `$_GET`, you have no `?` to start the query string with – Quentin Mar 24 '14 at 14:02
  • broken mod_rewrite? Your rewrite doesn't seem to like `%`: try changing the `[a-zA-Z0-9_-]` blocks to `[a-zA-Z0-9%_-]` – Mark Baker Mar 24 '14 at 14:02
  • these are mod_rewrite RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3 [L] RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([a-zA-Z0-9_]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4 [L] RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4&q=$5 [L] RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4&q=$5&r=$6 [L] – user3438880 Mar 24 '14 at 14:03
  • You can change your regex to search till it finds a slash, like you do with the first row. This way, it won't break your checks. Something like... `RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4&q=$5&r=$6 [L]` – Diamondo25 Mar 24 '14 at 14:05

2 Answers2

1

As Second Rikudo wrote, your rewrite rules are not accepting the & character (%26).

Try this;

RewriteRule ^([a-zA-Z0-9_-\&]{3,100})/([^/]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3 [L]
RewriteRule ^([a-zA-Z0-9_-\&]{3,100})/([^/]+)/([a-zA-Z0-9_\&]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4 [L]
RewriteRule ^([a-zA-Z0-9_-\&]{3,100})/([^/]+)/([a-zA-Z0-9_\&]+)/([a-zA-Z0-9_\&]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4&q=$5 [L]
RewriteRule ^([a-zA-Z0-9_-\&]{3,100})/([^/]+)/([a-zA-Z0-9_\&]+)/([a-zA-Z0-9_\&]+)/([a-zA-Z0-9\&]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4&q=$5&r=$6 [L]

Also, these rewriterules are not really efficient. I would go with something like this;

RewriteRule ^(.*)$ index.php?route=$1 [L]

And then do all the matching in PHP. There are a lot of frameworks that have excellent routing built in, you can use that or build your own, using something like the explode() function in PHP.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Rob
  • 4,927
  • 4
  • 26
  • 41
  • Getting internal server error using your rewrite rules RewriteRule ^([a-zA-Z0-9_-\&]{3,100})/([^/]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3 [L] RewriteRule ^([a-zA-Z0-9_-\&]{3,100})/([^/]+)/([a-zA-Z0-9_\&]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4 [L] RewriteRule ^([a-zA-Z0-9_-\&]{3,100})/([^/]+)/([a-zA-Z0-9_\&]+)/([a-zA-Z0-9_\&]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4&q=$5 [L] RewriteRule ^([a-zA-Z0-9_-\&]{3,100})/([^/]+)/([a-zA-Z0-9_\&]+)/([a-zA-Z0-9_\&]+)/([a-zA-Z0-9\&]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4&q=$5&r=$6 [L] – user3438880 Mar 24 '14 at 14:18
  • Yes, because the '-' not is the last char in list. – gabrieloliveira Mar 24 '14 at 14:19
0

The problem is than & (amperstand) char is a special char to apache (it separe parameters). So to identify this, use the [B] flag (In your case, append it after [L]:

RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3 [L,B]
RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([a-zA-Z0-9_]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4 [L,B]
RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4&q=$5 [L,B]
RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4&q=$5&r=$6 [L,B]

The write rules works, is second group than matches "s" parameter: /([^/]+)/, it can replace by /.+/. Works well to, I tested.

Based on: htaccess rewrite rule with escaped ampersand in $_GET fails

Community
  • 1
  • 1
gabrieloliveira
  • 560
  • 3
  • 10
  • I tried your rules with B flag but still it is giving wrong result check here http://www.industrialstores.com/search_results/Bell+%26+Gossett+101238+1.25%22+Sweat+ChecktroLFlangeset/46 – user3438880 Mar 24 '14 at 15:49
  • Post your .htaccess. And they have a "RewriteEngine On" in first line? – gabrieloliveira Mar 24 '14 at 15:52
  • RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3 [L,B] RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([a-zA-Z0-9_]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4 [L,B] RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4&q=$5 [L,B] RewriteRule ^([a-zA-Z0-9_-]{3,100})/([^/]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3&p=$4&q=$5&r=$6 [L,B] – user3438880 Mar 24 '14 at 15:55
  • I tried without RewriteEngine On but still same thing – user3438880 Mar 24 '14 at 15:58
  • No, RewriteEngine On have to present in .htaccess. Test without RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ %{HTTP_HOST}/$1 [R=301,L] – gabrieloliveira Mar 24 '14 at 16:00
  • I corrected this issue before encoding the url using $keyword = str_replace("&","%26",$keyword); $keyword = urlencode(str_replace("/","%2F",$keyword)); it works for me – user3438880 Mar 24 '14 at 16:09
  • So your problem is solved? You replace the '&' for other char and on decode your replace per '&' again, is this? – gabrieloliveira Mar 24 '14 at 16:12
  • Yes, something like this as I replaced & with %26 and on encoding it becomes %2526 and I got url like this http://www.industrialstores.com/search_results/Bell+%2526+Gossett+2NFI+Iron+Booster+Pump/46 My httaccess decodes this as I want – user3438880 Mar 24 '14 at 16:20
  • Cool, the problem is because '&' is a special char for apache. I tested with [B] flag and work but if for you not work, this workarround resolve the problem. – gabrieloliveira Mar 24 '14 at 16:24