Hi,
I am trying to create a RewriteRule for my site. I got the first part correctly. This means say /index.php?mid=#. This passes correctly.
Here is the example: http://www.orchot-hagilboa.com/דף_הבית

But how do I add another param?
Say I am passing /index.php?mid=#&smid=# ????

Here is my rewriterule in htaccess:

Options +FollowSymlinks
RewriteEngine On
#RewriteCond %{REQUEST_URI} !img/(.*)$
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.+)$ /index.php?q=$1 [L]

Here is what i do with the params:

//preparing query chunks 
$url = $_GET['q'];
$url = str_replace('_', ' ', $url);
$urlChunksInitial = explode('/', $url);
$urlChunks = array_reverse($urlChunksInitial);


//processing mid chunk 
if (isset($urlChunks[0]) && ($urlChunks[0] != '')) {

	$midTitle = $urlChunks[0];
	$midQuery = mysql_query('SELECT menu_id, title FROM menu WHERE title = \'' . $midTitle . '\'') 
		or trigger_error('Query: ' . $midQuery . '\n<br />MySQL Error: ' . mysql_error());
	if (mysql_num_rows($midQuery) > 0) {
		$midRows = @mysql_fetch_array($midQuery);
		$mid = $midRows[0];
		$menuTitle = $midRows[1];
		$menuUrl = '/'.$midRows[1];
	}

} // if ($urlChunks[0] != '')

// processing smid chunk 
if (isset($urlChunks[1]) && ($urlChunks[1] != '')) {

	$smidTitle = $urlChunks[1];
	$smidQuery = mysql_query('SELECT smenu_id, title FROM smenu WHERE title = \'' . $smidTitle . '\'') 
		or trigger_error('Query: ' . $smidQuery . '\n<br />MySQL Error: ' . mysql_error());
	if (mysql_num_rows($smidQuery) > 0) {
		$smidRows = @mysql_fetch_array($smidQuery);
		$smid = $smidRows[0];
		$smenuTitle = $smidRows[1];
		$smenuUrl = '/'.$smidRows[1];
	}

} // if ($urlChunks[1] != '')

Please help!!! :)

Recommended Answers

All 6 Replies

Hi,
I am trying to create a RewriteRule for my site. I got the first part correctly. This means say /index.php?mid=#. This passes correctly.
Here is the example: http://www.orchot-hagilboa.com/דף_הבית

But how do I add another param?
Say I am passing /index.php?mid=#&smid=# ????

Here is my rewriterule in htaccess:

Options +FollowSymlinks
RewriteEngine On
#RewriteCond %{REQUEST_URI} !img/(.*)$
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.+)$ /index.php?q=$1 [L]

<snip>

Please help!!! :)

Hello mate.

Here is how your .htaccess should look to add the extra functionality you want:

Options +FollowSymlinks
RewriteEngine On
#RewriteCond %{REQUEST_URI} !img/(.*)$
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.+)/^(.+)$ /index.php?q=$1&q2=$2 [NC] 
RewriteRule ^(.+)$ /index.php?q=$1 [NC]

you will now be able to access the second variable in your script as q2 if theres 2 matches, but if theres not 2 matches it will go to the next lin in the htaccess and look for 1 match

when i add this line

RewriteRule ^(.+)/^(.+)$ /index.php?q=$1&q2=$2 [NC]

i get Internal Server Error.
any ideas?

when i add this line
i get Internal Server Error.
any ideas?

hey yeh

try it without the additional ^ that i forgot to remove :-)

soo.....

RewriteRule ^(.+)/(.+)$ /index.php?q=$1&q2=$2 [NC]

i made the change, but i still get internal server error.

i made the change, but i still get internal server error.

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^en/([a-zA-Z0-9_]*)/([a-z0-9_]*)/([a-z0-9_]*)/([a-z0-9_]*)/([a-z0-9_]*)/([a-z0-9_]*)/([a-z0-9_]*)/ index.php?uid=$1&step=$2&function=$3&v1=$4&v2=$5&v3=$6&v4=$7 [NC]

RewriteRule ^en/([a-zA-Z0-9_]*)/([a-z0-9_]*)/([a-z0-9_]*)/([a-z0-9_]*)/([a-z0-9_]*)/([a-z0-9_]*)/ index.php?uid=$1&step=$2&function=$3&v1=$4&v2=$5&v3=$6 [NC]

RewriteRule ^en/([a-zA-Z0-9_]*)/([a-z0-9_]*)/([a-z0-9_]*)/([a-z0-9_]*)/([a-z0-9_]*)/ index.php?uid=$1&step=$2&function=$3&v1=$4&v2=$5 [NC]

RewriteRule ^en/([a-zA-Z0-9_]*)/([a-z0-9_]*)/([a-z0-9_]*)/([a-z0-9_]*)/ index.php?uid=$1&step=$2&function=$3&v1=$4 [NC]

RewriteRule ^en/([a-zA-Z0-9_]*)/([a-z0-9_]*)/([a-z0-9_]*)/ index.php?uid=$1&step=$2&function=$3 [NC]

RewriteRule ^en/([a-zA-Z0-9_]*)/([a-z0-9_]*)/ index.php?uid=$1&step=$2 [NC]

thats a working htaccess on my server.... i don't have time at the minute to test your problem but maybe my htaccess can point you in the right direction. hope this helps! :-)

thanks for the code. im not sure why its not working

RewriteRule ^([a-zA-Z0-9_]*)/([a-z0-9_]*) /index.php?q=$1&step=$2 [NC]
RewriteRule ^([a-zA-Z0-9_]*) /index.php?q=$1 [NC]

The last line works, but the first doesn't.

i dont get it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.