Select box - page not found error htaccess

hi all

i have this is my htaccess


RewriteRule ^items-([0-9]+)-([0-9]+)-([^/\\.]+)-([^/\\.]+)$  items.php?dler_id=$1&ctgry_id=$2&page=$3&choice=$4

url i get is


http://localhost/foldername/items-8-1-1-high

When i paste the above url address in the addressbar then the page is displayed absolutely fine.

but when i choose option from the select box and click submit then i get


"page not found" error

this is my select box code



<? 
$choice = $_REQUEST['choice'];
$urlg = "http://localhost/foldername/items-".$dler_id."-".$ctgry_id."-1-"."$choice"; 
/* output = http://localhost/foldername/items-8-1-1-high */
?>

<form id="sortform" name="sortform" action="<? echo $urlg ?>" method="post">
<select class="sortselect" name="choice" id="choice">
<option value="high">Price high to low</option>
<option value="low">Price low to high</option>
</select>
<input name="submit" id="submit" type="submit" value="" />
</form>


vineet

vineet,

I’ll not worry that you have no text in your submit button but go straight to the mod_rewrite code.


RewriteRule ^items-([0-9]+)-([0-9]+)-([^/\\.]+)-([^/\\.]+)$  items.php?dler_id=$1&ctgry_id=$2&page=$3&choice=$4

First, kudos to you for understanding enough to NOT use the dreaded (.*) to match garbage.

Second, no Last flag?

Third, you do not need to (therefore, you should not) escape the dot character within a character range definition.

Lastly, on the assumption that you only use the .htaccess in the DocumentRoot (here, that’s localhost), your leading start anchor is ignoring the folder in your URI and is, therefore, failing to match your URI and performing the redirection.

Only the last “error” (failing to account for the folder in your RewriteRule) will prevent your code from working. Hint: deleting the ^ will have the same effect as implementing this code for every subdirectory else add folder/ after the start anchor. If your .htaccess is within the folder directory, then you may need to add a leading / - I’d make that /? as subdirectories handle the leading / differently and I’m too tired to remember if it’s required here or not.

Regards,

DK

hi dk

All my webpages including .htaccess file are in same “folder”.

so it should match the url.

But it didnt matched in my case.

no files exists directly under localhost

vineet

vineet,

Okay, then the last paragraph above applies.

Of course, I should mention that you can (SHOULD) create virtual hosts on your development machine as it’s both simple and highly effective when testing your domains (locally). To do that, you’ll need to edit the httpd.conf file to include the extras/httpd-vhosts.conf file, you’ll need to add your localhost’s domain with the path to your localhost domain (WARNING: Do NOT use the fully qualified domain name, e.g., for dk.co.nz I used dk), edit your windows\system32\drivers\etc\hosts file to include 127.0.0.1 domain and restart Apache.

Regards,

DK

hi dk

one last question

whats the drawback of not using Last flag [L]

what happens if i dont use [L] Flag

Is it mandatory to mention [L] to all my rewrite rules.

If there are 10 rewrite rules then i have to mention [L] for all 10 rewrite rules.

vineet

vineet,

“I thought I was wrong once but I was mistaken.” :lol:

I used to believe that mod_rewrite ANDed successive RewriteRules … but that is INCORRECT!

The point of the Last flag is to direct mod_rewrite to begin its next pass through your code before going through the remainder of your mod_rewrite code.

I still have the mindset that the Last flag is as necessary as the ; in PHP but, IF there is a reason to run other directives with the updated {REQUEST_URI} string before the next iteration (which will run that code anyway), by all means, do so. The timing advantage of restarting immediately is surely minimal.

Regards,

DK