Page 1 of 2

301 Redirect going to Long URL - why?

Posted: Mon Jul 14, 2014 5:36 am
by simonmlewis

Code: Select all

DirectoryIndex index.php index.html index.htm 
order allow,deny
allow from all 

ErrorDocument 404 /home

Options +FollowSymLinks
Options +Indexes
RewriteEngine On

Redirect 301 /blog/comments/feed/ http://www.site.ie/error
Hi.
We are adding a load of 301s, but rather than going to /error, they are going to /error?page=.......
What it is also doing, is if the bad URL is a shorturl, the URL shown after error?.... is the LONG url version?!?!?!?!

Am I doing the 301 correctly, should it be placed after all the other mod rewrites?

Re: 301 Redirect going to Long URL - why?

Posted: Mon Jul 14, 2014 12:14 pm
by requinix
You are doing it somewhat correctly but it might not be what you want it to do. Redirect works by taking everything after the .../feed/ and appending it to the /error, so if there's a query string then you'll get it appended on the error URL too.

Redirects suck. How about doing the "redirect" internally? The user sees the same URL but they get the error page. Use mod_rewrite instead of a Redirect.

Code: Select all

RewriteEngine on
RewriteRule ^/?blog/comments/feed/ <whatever page actually handles "/error"> [L]

Re: 301 Redirect going to Long URL - why?

Posted: Tue Jul 15, 2014 3:16 am
by simonmlewis
No that isn't a "301", that's just telling it to take one page to another.
We need to tell Google that the page is wrong, and it's permanently going to /error instead.

Why would our code be rewritting the URL in "long" form aswell??

Re: 301 Redirect going to Long URL - why?

Posted: Tue Jul 15, 2014 3:27 am
by requinix
simonmlewis wrote:No that isn't a "301", that's just telling it to take one page to another.
We need to tell Google that the page is wrong, and it's permanently going to /error instead.
That's right: you do need to tell Google the page is wrong. But the way you do that is not with a 301 but with a 404. Which would be served by that error page - which I assumed it was already doing.

A redirect of any sorts is the wrong message to send. Leave the URL the same and serve an error page with a 404 instead. Do that either by having the site code realize the requested page does not exist, or in this case by rewriting to the error page.
simonmlewis wrote:Why would our code be rewritting the URL in "long" form aswell??
"Long form"? You mean a filename? Because that's what mod_rewrite wants to get: a filename. Which is because Apache already had a filename by that point and doesn't want to have to look up yet another URL. Not to say a subrequest (URL lookup) is impossible, it's just less desirable.

Re: 301 Redirect going to Long URL - why?

Posted: Tue Jul 15, 2014 3:31 am
by simonmlewis
We have been told by our guys that we need to do a 301, that tells Google what to do.
Therefore this is what we need it to do - a Redirect 301 from a > b.

How would we do multiple 404s in HTACCESS to cover over a thousand pages?

Re: 301 Redirect going to Long URL - why?

Posted: Tue Jul 15, 2014 3:47 am
by simonmlewis

Code: Select all

DirectoryIndex index.php index.html index.htm 
order allow,deny
allow from all 

ErrorDocument 404 /home

Options +FollowSymLinks
Options +Indexes
RewriteEngine On

Redirect 301 /simon http://www.site.ie/home
Here is a great example. This takes me to:
[text]http://www.site.ie/home?page=simon&menu=home[/text]

Re: 301 Redirect going to Long URL - why?

Posted: Tue Jul 15, 2014 4:19 am
by requinix
Huh. At 2am I don't seem to care about the quality of the SEO advice you're receiving.

Like I said earlier, Redirect will add the query string. IIRC you can tell mod_rewrite not to do that, though I'm not sure whether it'll redirect you to literally "/error?".

Code: Select all

RewriteEngine on
RewriteRule ^/?blog/comments/feed /error? [L,R=301]
Now, what does that example have to do with anything? Have you changed your mind about how this page we've been looking at should redirect?

Re: 301 Redirect going to Long URL - why?

Posted: Tue Jul 22, 2014 3:52 am
by simonmlewis
301 just are not working for us,. but standard redirections are really doing the trick. But here's one that will not work for us:

Code: Select all

DirectoryIndex index.php index.html
order allow,deny
allow from all 

Options +FollowSymLinks
Options +Indexes
RewriteEngine On

RewriteRule ^categ/page///1/?$ index.php?page=selectpage&menu=home [L]
This just goes to a full on
[text]Not Found
The requested document was not found on this server. [/text]
...page.

Re: 301 Redirect going to Long URL - why?

Posted: Tue Jul 22, 2014 6:28 am
by Celauran
simonmlewis wrote:

Code: Select all

RewriteRule ^categ/page///1/?$ index.php?page=selectpage&menu=home [L]
What is that supposed to match?

Re: 301 Redirect going to Long URL - why?

Posted: Tue Jul 22, 2014 6:40 am
by simonmlewis
It's meant to go to index.php?page=selectpage&menu=home.

Re: 301 Redirect going to Long URL - why?

Posted: Tue Jul 22, 2014 6:46 am
by Celauran
I meant the regex at the beginning. ^categ/page///1/?$

http://yoursite.co.uk/categ/page///1 seems a pretty unlikely URL.

Re: 301 Redirect going to Long URL - why?

Posted: Tue Jul 22, 2014 6:50 am
by simonmlewis
Youv'e lost me.....
the /// is completely wrong, BUT Google has cached it at some stage, so need to tell it to go elsewhere.

Re: 301 Redirect going to Long URL - why?

Posted: Wed Aug 27, 2014 9:03 am
by simonmlewis
The other part of this issue now is an entry I am trying like this:

Code: Select all

RewriteRule ^ip_mobilehome.php?url=http://www.site.co.uk/product/512/HOLD/312/HOLD/372/R9-P90S/?$  index.php?page=selectpage&menu=home [L]
It won't go to the 'selectpage' URL, it goes to ip_mobilehome.php.

Why??

It works for most other URLs we are trying to 301.

Re: 301 Redirect going to Long URL - why?

Posted: Wed Aug 27, 2014 9:22 am
by jdhmtl
Something like this, perhaps?

Code: Select all

RewriteCond %{REQUEST_URI} ip_mobilehome.php
RewriteCond %{QUERY_STRING} ^url=http://www.site.co.uk/product/512/HOLD/312/HOLD/372/R9-P90S/?$
RewriteRule (.*)  index.php?page=selectpage&menu=home [L]

Re: 301 Redirect going to Long URL - why?

Posted: Wed Aug 27, 2014 9:42 am
by simonmlewis
Would you mind explaining each line of that?
We have over a 1000 lines like this that work, but only this one (tho there are about 600 of them) that have this problem.
It reads like I'd need line one of our code just once, and then line two for each error one.
And line three just once.