PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Aug 21, 2017 1:35 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Wed Jun 07, 2017 9:55 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4254
Location: United Kingdom
We have an issue were a ton of old URLs are appearing at 404s.
Some of these are legitimate 404s, as they don't exist at all, so 301ing those to another page is not necessarily the right thing to do.

But for others, like. www.domain.com/category/shirts/11/redshirt/favicon.ico.
We want to 301 that to /favicon.ico.

Trouble is, we have various rules set in HTACCESS to handle certain URL formats. So how do we add a rule after them all that just said, "or accept anything".... ??

So we can put in these dodgy urls and point them correctly elsewhere.

Another good example is we have current structure for : /categ/white-shirts.
Syntax: [ Download ] [ Hide ]
RewriteRule ^categ/([^/]+)$ /index.php?page=categ&cname=$1 [L]

But we are finding urls like: /mobile/ihome.

These are REALLY old when we had a mobile 'version' of the site.
So how do we handle this sort of URL issue?

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Wed Jun 07, 2017 6:47 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6493
Location: WA, USA
Don't redirect those. If /category/shirts/11/redshirt/favicon.ico does not exist then it does not exist. What you should be doing is deciding whether it's your fault that those URLs are being requested (eg, something is referencing "favicon.ico" instead of "/favicon.ico") and correcting that, but if it isn't your fault then let it 404.


Top
 Profile  
 
PostPosted: Thu Jun 08, 2017 2:51 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4254
Location: United Kingdom
Back about 4 years ago, we had older style of urls, and issues where we hadn't referred favicon.ico to /favicon.ico. So the URL was wrong.
The Code in the site is now correct for it, and has been for years.

We read about 404 increases being bad. But if the 404 goes to a proper nice "Sorry that page is not here, look at the menu at the top, click here for the homepage, or search here".... is that ok? So if you had 100, 200 404s, it would not matter, if the page really does not exist.

Then you only do 301s if the page SHOULD be pointing elsewhere.
And this is the problem.
We need to be able to add some 301s for URL structures we don't use. I know Wordpress handles structures very differently, as the HTACCESS file has very little in it.
But we used WP as an example of "why can we not 301 to any page".

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Thu Jun 08, 2017 3:27 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6493
Location: WA, USA
simonmlewis wrote:
Back about 4 years ago, we had older style of urls, and issues where we hadn't referred favicon.ico to /favicon.ico. So the URL was wrong.
The Code in the site is now correct for it, and has been for years.

You aren't obligated to support URLs for eternity. If it's been 4 years since you changed it then people (clients, search engines, bots, whatever) have had that long to figure out they should stop requesting the old favicon path. Changing it from 404 to 301 isn't suddenly going to make them change their ways.

simonmlewis wrote:
We read about 404 increases being bad. But if the 404 goes to a proper nice "Sorry that page is not here, look at the menu at the top, click here for the homepage, or search here".... is that ok? So if you had 100, 200 404s, it would not matter, if the page really does not exist.

You're talking about two different things.

1. Increases in 404s are bad. It's not because 404s themselves are bad but because the increase is a symptom of a potential bug in your site and that is bad.
2. Making the 404 page be helpful to the user is important. They shouldn't see these pages normally, and wouldn't in the case of a favicon (so a minimal 404 for such resources is fine), but it will happen so you should try to help people find what they were looking for. You would use 3xx redirects when deprecating old URLs so that automated systems can detect the change and recover gracefully, but after a while - like four years - it's okay to stop redirecting.

simonmlewis wrote:
Then you only do 301s if the page SHOULD be pointing elsewhere.

Not sure if you're intentionally getting into the technical nature of a 301, but yes: for the act of redirecting you do need someplace to redirect to. But that's besides the point here. The point I'm trying to make is not that you could redirect to /favicon.ico but that you don't need to. It's an old URL. It hasn't been supported in years, deliberately or not. Redirecting (as far as this conversation goes) is a graceful measure to ease transitions to new URLs, not an obligation to backwards compatibility.

simonmlewis wrote:
We need to be able to add some 301s for URL structures we don't use. I know Wordpress handles structures very differently, as the HTACCESS file has very little in it.
But we used WP as an example of "why can we not 301 to any page".

.htaccess redirects don't care about WordPress, and WordPress doesn't really care about .htaccess redirects. All you need to concern yourself with is the URL as seen in the browser: if you want to redirect (and WP itself doesn't provide an adequate mechanism to do so) then you do that with a Redirect directive or mod_rewrite; as long as you instruct it to perform an external redirect, like with [R=301], then WordPress/your code won't even know it happened.


Top
 Profile  
 
PostPosted: Thu Jun 08, 2017 4:01 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4254
Location: United Kingdom
But if our structure in HTACCESS doesn't allow for /mobile/ihome, because for example, /categ/shirts is using that style in a rule already, how do we 301 it?

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Thu Jun 08, 2017 4:17 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6493
Location: WA, USA
Then redirect that particular URL. A Redirect may be fine if you've moved the /mobile/ihome root to somewhere else, otherwise mod_rewrite.

I don't get what the problem is: if you want to redirect /mobile/ihome then do that. The fact that it has the same /dir1/dir2 structure as /categ/shirts should be irrelevant.


Top
 Profile  
 
PostPosted: Thu Jun 08, 2017 4:31 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4254
Location: United Kingdom
Are you saying to literally HARD CODE it into HTACCESS?
As at the moment we have a 301 tool that does in in PHP. But obviously, to get there is passes thru HTACCESS first, and if that url is not in a format that is accepted as present in HTACCESS, it ignores it.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Thu Jun 08, 2017 5:22 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6493
Location: WA, USA
I'm getting tired of half truths and partial details.

simonmlewis wrote:
Are you saying to literally HARD CODE it into HTACCESS?

You're the one saying you need to redirect /mobile/ihome. If you're actually trying to say you need to redirect a number of URLs such as /mobile/ihome that all follow a similar pattern then that's different.

simonmlewis wrote:
As at the moment we have a 301 tool that does in in PHP.

Did you implement that in the last few hours? Because until now we've been talking about doing 301s in .htaccess. Do you want to change the subject to be how to make these URL patterns go through to your 301 tool thing so you can do the redirects there instead?


Normally front controller-type setups have all non-existent requests going through the codebase. Not particular URL patterns. That's how they can do things like handle redirects and 404s intelligently. By the sounds of it that is not what you're doing. So either you switch to that paradigm or you continue putting specific details about your URL structures and pages into the .htaccess.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group