Mod_rewrite 404 error when dot is in URL, please help!

Hi Everyone!

I’m having a big problem with one rule in the .htaccess file:

This rule it’s working perfectly
RewriteRule ^([^\.]+)/([^\.]+)/([^\.]+)/([^\.]+)$ /test.php?RecordID=$4
with a URL like this:
domain.com/Shoes/ADIDAS/Adidas-Mens-Tech-Response-30/2214

But, when the name of the product have a . (dot) like
domain.com/Shoes/ADIDAS/Adidas-Mens-Tech-Response-3.0/2214

I had an error 404… I searched all the web and I can’t find a solution…

If someone could help I will really apreciate!

Thank you!

Leo

0o,

Your last atom forbids the dot character - remove it from the character list exclusion and it’ll match (and redirect).

Regards,

DK

Thank you DK!

I changed the 3rd atom…

RewriteRule ^([^\.]+)/([^\.]+)/(.*)/([^\.]+)$ /products_detail.php?RecordID=$4

And it work perfectly… please if there is a better solution I will glad to use it.

Please just one more question… what happend if there is a special simbol like # in the url? It could be a problem?

Best Regards!

Leo

0o,

would be a MAJOR problem as it’s a reserved character with meaning only within a browser (looking for an in-page anchor).

[begin rant #1]Better solution? YES! Using the dreaded :kaioken: EVERYTHING :kaioken: atom, the (.) as well as its derivatives as you have done can only lead to problems. IMHO, learning real (not “lazy”) regex will help you to avoid the problems. I keep myself out of trouble (most of the time) by specifying EXACTLY which characters will be allowed in any atom. When you specify what characters you DON’T want included, you’re telling Apache that EVERYTHING else (or nothing else in the (.) case) is fine for you. You’ll learn that restricting inane combinations via proper regex is a lot easier than correcting the garbage in your scripts. If you’re looking for a place to start, try my signature’s tutorial.[end rant #1]

Regards,

DK

DK,

I will read (again) more from your tutorial… thank you for your advice!

About the # I will take off from the string with php.

Thank you very much for your help!

Regards!

Leo

0o,

Thanks for taking my #1 rant in the vein that it was meant: helpful. I know I get carried away with my ranting about this but it does get the message across.

I’m not sure whether it’s in your defense or not but the simple fact that you are using FOUR of these things REQUIRES your URI to use three subdirectory levels plus a filename. It’s that “structure” which is the only thing that’s saving you from the normal loop. Remember, products_detail.php (and the normal index.php) is matched by (.) so special care must ALWAYS be taken when using the EVERYTHING atom to exclude the redirection from the (.).

Regards,

DK

DK, that’s ok… I’m a newbbie in this matter… so I’m trying to learn fast… it’s incredible the things that you can do with the mod_rewrite…

This is how I polished the code… not sure if is the best way… but I did something more specific than the other day…

RewriteEngine On
RewriteRule ^([-a-zA-Z_]+)/([-a-zA-Z_]+)/([-a-zA-Z0-9_]+)/([0-9]+)$ /products_detail.php?RecordID=$4
RewriteRule ^([A-Z]+)/([-a-zA-Z_]+)/([-a-zA-Z_]+)$ /products_brand_search.php?BrandID=$3&CatID=$2
RewriteRule ^([A-Z]+)/([-a-zA-Z_]+)$ /products_brand.php?BrandID=$2
RewriteRule ^([-a-zA-Z_]+)$ /products_cat.php?CatID=$1 [L]

Thank you for your time!

Regards!

Leo

0o,

PERFECT! Okay, I have to whine about something so let me pick on the leading / in the redirection. Occasionally, that will upset Apache as it can confuse that with the physical address system (only when Apache already has a problem, it seems). Best to omit that WHEN YOUR .htaccess IS IN THE DocumentRoot. Just a suggestion, though, as you’ve learned a lot!

Regards,

DK