Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite problem

mod rewrite not working with period

         

kunwarbs

3:45 pm on Oct 4, 2006 (gmt 0)

10+ Year Member



The following rewrite rule works fine while I use the url in the following format
[domain.com...]

however, if my product name contains a period (.), the rewrite rule doesn't work. Underscores and hyphens are also working fine.

What's wrong with the following rewrite rule?

RewriteRule ^dir/([_a-z0-9-]+)/?$ /dir/product_details.php?product_id=$1

jdMorgan

5:23 pm on Oct 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The "([_a-z0-9-]+)" pattern does not contain a period, so therefore it will not match and the rule will not be applied if one is present.

I'd suggest:


([_a-z0-9-.]+)

Jim

kunwarbs

5:28 pm on Oct 4, 2006 (gmt 0)

10+ Year Member



I tried that but that gives internal server error

also tried with [_a-z0-9-\.] but that too didn't work.

jdMorgan

5:46 pm on Oct 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In that case, it may be best to try escaping all special regex token characters:

([_a-z0-9\-\.]+)
or
([a-z0-9_.\-]+)
etc.

I suspect that regex saw "9-." and got confused as to whether "0-9" was a range expression, or "9-." was a range expressions, or both.

Jim

kunwarbs

5:33 pm on Oct 5, 2006 (gmt 0)

10+ Year Member



in that case, it may be best to try escaping all special regex token characters:

([_a-z0-9\-\.]+)
or
([a-z0-9_.\-]+)
etc.

This didn't worked either :(

jdMorgan

5:42 pm on Oct 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please be very specific: Did it cause a 500-Server Error, or simply fail to rewrite your URL with a dot in it?

If the latter, be sure to flush your browser cache (Temporary Internet Files) before testing after *any* change to your configuration files.

Jim

DrDoc

5:44 pm on Oct 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps escape your slashes

^dir\/([_a-z0-9\-\.]+)\/?$

[edited by: DrDoc at 5:45 pm (utc) on Oct. 5, 2006]

kunwarbs

4:40 am on Oct 6, 2006 (gmt 0)

10+ Year Member



Please be very specific: Did it cause a 500-Server Error, or simply fail to rewrite your URL with a dot in it?

It generated Error 500- Internal Server Error

experienced

10:02 am on Oct 6, 2006 (gmt 0)

10+ Year Member



is it possible to use url rewrite mode in IIS instead of apache server...?

jdMorgan

3:48 pm on Oct 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



kunwarbds,
Check your server error log for the entries created by the 500-Server Error. They may give a good idea of what the problem is. That code should work fine on 99% of all Apache servers.

experienced,
See ISAPI Rewrite for IIS -- It is an inexpensive module you can buy and install on MS servers to do many of the things that mod_rewrite on Apache can do. It's easy to find with a search for "ISAPI Rewrite".

Jim

kunwarbs

6:13 pm on Oct 6, 2006 (gmt 0)

10+ Year Member



[.a-z0-9-]
when i use period ALONE, it works but gives 500-Internal Server Error with underscore and/or hyphen.

I have finally put two rewrite rules - one for period (.) and another for underscore and hyphen

RewriteRule ^dir/([_a-z0-9-]+)/?$ /dir/product_details.php?product_id=$1
RewriteRule ^dir/([.a-z0-9-]+)/?$ /dir/product_details.php?product_id=$1

Just wanted to know if this will put any negative implication?

or shall i use [L] after teh rewrite rule?

RewriteRule ^dir/([_a-z0-9-]+)/?$ /dir/product_details.php?product_id=$1 [L]
RewriteRule ^dir/([.a-z0-9-]+)/?$ /dir/product_details.php?product_id=$1 [L]

jdMorgan

7:12 pm on Oct 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use [L] unless you want or need the output of the current rule to be rewritten again by rules that follow.

If you are having trouble with hyphen, underscore, and period when combined in a [_.-] group, I suspect there's something wrong with your mod_rewrite or regular-expressions library installation, or that you've got obsolete versions. I can combine them in any way I like without causing errors on my servers. Very strange...

Again, the information in your server error log might be very useful...

Jim