Page 1 of 3

Period . sends page to 404, but only on some URLs..

Posted: Mon Nov 07, 2016 9:56 am
by simonmlewis
We are building filters for a website.
Some of the filters have full stops in them. ie. 0.77 CAL.
In the URL, that is converted into /all-products&calibre=0.77-cal.
If I go to that page, I get a 404 error.
However, if I use that same query on the end on a category page, or a search page as follows, I don't get a 404.

/index.php?page=guns&category=all&calibre=0.77-cal
/categ/special-ops&calibre=0.77-cal

This is the HTACCESS rewrite for the one with the issue:
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]

This is it for the category that works:
RewriteRule ^categ/([^/]+)$ /index.php?page=categ&cname=$1 [L]

If I use a calibre filter that has no . in it, it works.

Re: Period . sends page to 404, but only on some URLs..

Posted: Mon Nov 07, 2016 9:59 am
by Celauran
simonmlewis wrote: In the URL, that is converted into /all-products&calibre=0.77-cal.
...
/categ/special-ops&calibre=0.77-cal
Shouldn't those & be ?

Re: Period . sends page to 404, but only on some URLs..

Posted: Mon Nov 07, 2016 10:02 am
by Celauran
simonmlewis wrote: This is the HTACCESS rewrite for the one with the issue:
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
That rule will not match this URI: /categ/special-ops&calibre=0.77-cal
That rule reads "line begins with any number of characters that are not a forward slash or a full stop and optionally ends with a forward slash"

Re: Period . sends page to 404, but only on some URLs..

Posted: Mon Nov 07, 2016 10:03 am
by Celauran

Re: Period . sends page to 404, but only on some URLs..

Posted: Mon Nov 07, 2016 10:10 am
by simonmlewis
So I need to alter than rule to allow for a period?

Re: Period . sends page to 404, but only on some URLs..

Posted: Mon Nov 07, 2016 10:29 am
by Celauran
Well yes. Deliberately excluding full stops from a rule when you're expecting them in the URI is counterproductive.

Re: Period . sends page to 404, but only on some URLs..

Posted: Mon Nov 07, 2016 10:40 am
by simonmlewis
Sorry I worded that wrong. So how do I INCLUDE full stops to be eligible in the URL?

Re: Period . sends page to 404, but only on some URLs..

Posted: Mon Nov 07, 2016 10:45 am
by Celauran
You need to remove the \. from your exclude list, but you also need to allow for the category. Hard for me to say exactly what your rule should be without knowing about other use cases. Have you looked at the htaccess tester I linked earlier? Considered implementing a router so you're not stuck dealing with so much htaccess?

Re: Period . sends page to 404, but only on some URLs..

Posted: Mon Nov 07, 2016 10:49 am
by Celauran
Something like this could work
[text]RewriteRule ^categ/([^\/]+)/?$ index.php?categ=$1 [QSA,L][/text]
but I have no way of knowing how it will interact with your other rules.

Re: Period . sends page to 404, but only on some URLs..

Posted: Mon Nov 07, 2016 10:56 am
by simonmlewis
The category works fine.
It's the root one that fails. so /all-product&calibre=0.77-cal
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]

Re: Period . sends page to 404, but only on some URLs..

Posted: Mon Nov 07, 2016 10:58 am
by Celauran
Still need to remove the full stop exclusion, so
[text]RewriteRule ^([^/]+)/?$ index.php?page=$1 [L][/text]

Re: Period . sends page to 404, but only on some URLs..

Posted: Mon Nov 07, 2016 11:10 am
by simonmlewis
RewriteRule ^([^/]+)/?$ index.php?page=$1 [L]
This is disallowing ALL URLs that are just /home for example.
This isn't live so there is no major panic here. But I don't know why it would cause that.

Right at the very top of the file is this, which I believe is to do with casing, but it has a full stop. could this be affecting it?

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

Re: Period . sends page to 404, but only on some URLs..

Posted: Mon Nov 07, 2016 11:15 am
by Celauran
Let's back up a second before we get too deep down the htaccess rabbit hole. What is it specifically that you're trying to do and is this rule even required?

Re: Period . sends page to 404, but only on some URLs..

Posted: Mon Nov 07, 2016 11:27 am
by simonmlewis
Ok. This is for a website that sells products.
We have filters (mentioned in another thread).
There are filters where the filter is for "calibre", and could be 0.77 CAL. Mostly with a full stop in them.
On Categories, the filter works.
On this page, which is /all-products, it has the filter, but when you select any filter with the full stop it in, it goes to a 404. (a custom 404 i might add).

Re: Period . sends page to 404, but only on some URLs..

Posted: Mon Nov 07, 2016 11:30 am
by Celauran
So where does htaccess even fit into this? Why isn't /all-products?calibre=0.77-cal sufficient?