htaccess rewrite rule with forward slash error

Hello Experts-

I have an htaccess rewrite rule setup to rewrite urls for model numbers.

It looks like this:

RewriteRule ^([A-Z0-9:-]+).html$ ProductDetails.php?SKU=$1 [NC]

This works great except that some models have a forward slash in them which causes it to look like a new directory. Example model:  123/abc

I tried this rewrite:

RewriteRule ^([A-Z0-9:-^/^]+).html$ ProductDetails.php?SKU=$1 [NC]

which opens the page instead of a no page found, but the css and image files are missing.

How do I allow for a slash in the model?

Thanks for your help.
Who is Participating?
Brad HoweConnect With a Mentor DevOps ManagerCommented:
Hi Danjen,

Slash is an illegal character for a file name in all OS's. Lets say the file name is "123/abc".

This is default behaviour for browsers. It would be interpretted as an attempt to browse the file "abc" in the directory "123".

Cannot you not just make this a hyphen such as 123-abc?

Brad HoweDevOps ManagerCommented:
As per the css and image files missing. This would be a bug in the productdetails.php if productdetails.php can't resolve the path to the css/images.

danjenAuthor Commented:
Thanks - this solution worked.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.