Fix issue #999
diff --git a/system/core/Config.php b/system/core/Config.php
index 6563827..4b4e5a7 100644
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -235,14 +235,26 @@
 			return $this->slash_item('base_url').$this->item('index_page');
 		}
 
+		$uri = $this->_uri_string($uri);
+
 		if ($this->item('enable_query_strings') === FALSE)
 		{
 			$suffix = ($this->item('url_suffix') === FALSE) ? '' : $this->item('url_suffix');
-			return $this->slash_item('base_url').$this->slash_item('index_page').$this->_uri_string($uri).$suffix;
+
+			if ($suffix !== '' && ($offset = strpos($uri, '?')) !== FALSE)
+			{
+				$uri = substr($uri, 0, $offset).$suffix.substr($uri, $offset);
+			}
+			else
+			{
+				$uri .= $suffix;
+			}
+
+			return $this->slash_item('base_url').$this->slash_item('index_page').$uri;
 		}
-		elseif (is_array($uri) OR strpos($uri, '?') === FALSE)
+		elseif (strpos($uri, '?') === FALSE)
 		{
-			$uri = '?'.$this->_uri_string($uri);
+			$uri = '?'.$uri;
 		}
 
 		return $this->slash_item('base_url').$this->item('index_page').$uri;
diff --git a/system/core/URI.php b/system/core/URI.php
index 208d311..6a8b1a5 100644
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -302,9 +302,11 @@
 	 */
 	public function _remove_url_suffix()
 	{
-		if  ($this->config->item('url_suffix') !== '')
+		$suffix = (string) $this->config->item('url_suffix');
+
+		if ($suffix !== '' && ($offset = strrpos($this->uri_string, $suffix)) !== FALSE)
 		{
-			$this->uri_string = preg_replace('|'.preg_quote($this->config->item('url_suffix')).'$|', '', $this->uri_string);
+			$this->uri_string = substr_replace($this->uri_string, '', $offset, strlen($suffix));
 		}
 	}