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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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 ?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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"
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post by Celauran »

simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post by simonmlewis »

So I need to alter than rule to allow for a period?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post by Celauran »

Well yes. Deliberately excluding full stops from a rule when you're expecting them in the URI is counterproductive.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post by simonmlewis »

Sorry I worded that wrong. So how do I INCLUDE full stops to be eligible in the URL?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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.
Attachments
Screen Shot 2016-11-07 at 11.49.15 AM.png
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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]
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post by Celauran »

Still need to remove the full stop exclusion, so
[text]RewriteRule ^([^/]+)/?$ index.php?page=$1 [L][/text]
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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]
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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).
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post by Celauran »

So where does htaccess even fit into this? Why isn't /all-products?calibre=0.77-cal sufficient?
Post Reply