Page 1 of 2

HTACCESS 301 - how do you point, when current URL has // ?

Posted: Mon Feb 23, 2015 9:08 am
by simonmlewis
We have some Google Webmaster issues where there are URLs that have somehow been generated with missing characters in the URL.

I want to point them to the correct URL in HTACCESS, as there is a handful of them, but I don't know how to do it when the URL has // in it.

For example:
http://www.site.co.uk/subcateg//Big-Special//XL-Shirt/
I want to point that to, for example:
http://www.site.co.uk/subcateg/33/Big-S ... /XL-Shirt/

This doesn't work:

Code: Select all

RewriteRule ^subcateg//Big-Special//XL-Shirt//?$  /subcateg/544/Big-Special/449/XL-Shirt// [R=301,L]

Re: HTACCESS 301 - how do you point, when current URL has //

Posted: Mon Feb 23, 2015 9:13 am
by Celauran
Looks like it should, although I'd remove R=301 until it properly does. What else is in your .htaccess file? Probably another rule that's interfering. Also, http://htaccess.madewithlove.be/

Re: HTACCESS 301 - how do you point, when current URL has //

Posted: Mon Feb 23, 2015 9:20 am
by simonmlewis
I can remove that, yes, but there are LOADS on here, because even tho we take people to a "this page is no longer here, have you seen these products?" page if it's not found, Google sees it at a 404. so we are tidying up.

This rule however goes to an Object not found page, with 404 in the error.

Re: HTACCESS 301 - how do you point, when current URL has //

Posted: Mon Feb 23, 2015 9:24 am
by Celauran
I understand that, but 301 is a permanent redirect, whereas 302 is temporary. Telling Google about a permanent redirect that doesn't actually work is a pretty bad idea.

Re: HTACCESS 301 - how do you point, when current URL has //

Posted: Mon Feb 23, 2015 9:30 am
by simonmlewis
Fair enough. but it won't work at all, because of the //.

Re: HTACCESS 301 - how do you point, when current URL has //

Posted: Mon Feb 23, 2015 9:39 am
by Celauran
Have you checked the link I posted above? Have you pasted your whole .htaccess into it? Might help reveal the error for you. Barring that, post it here and we can take a look. That rule alone looks fine.

Re: HTACCESS 301 - how do you point, when current URL has //

Posted: Mon Feb 23, 2015 9:55 am
by simonmlewis
Yes, with QSA on the end, it reckons the rule was met, but the page still goes to a 404 Object not Found.
No other errors in my HTACCESS.

It seems if there is a // in the URL, it just won't have it.

Re: HTACCESS 301 - how do you point, when current URL has //

Posted: Mon Feb 23, 2015 9:58 am
by Celauran
simonmlewis wrote:It seems if there is a // in the URL, it just won't have it.
That's clearly not the case. Not much else I can suggest when your .htaccess is a black box, though.

Re: HTACCESS 301 - how do you point, when current URL has //

Posted: Mon Feb 23, 2015 10:04 am
by simonmlewis
Maybe I should try to strip back the HTACCESS locally to see if something else is causing it to fail on that line. Or at least PHP isn't doing what it's told correctly by HTACCESS.

Re: HTACCESS 301 - how do you point, when current URL has //

Posted: Mon Feb 23, 2015 10:07 am
by Celauran
Yes. Remove all other rules and see if the redirect works. Then you can start adding them back to see which rule is causing the conflict.

Re: HTACCESS 301 - how do you point, when current URL has //

Posted: Mon Feb 23, 2015 10:27 am
by simonmlewis
Right, I have stripped virtually the lot out of here. Even the structure code for the product and category pages.

But even this causes the:
Object not found!

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.
Error 404
site.local
Apache/2.4.4 (Win32) OpenSSL/1.0.1e PHP/5.5.1

Code: Select all

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

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^subcateg//BIG-STYLE//SHIRTS//?$  /subcateg/544/BIG-STYLE/449/SHIRTS/ [R=301,L]

RewriteRule ^mobile(.*)/? /selectpage [L,R=301]
RewriteRule ^subcateg/([0-9]+)/([^/]+)/([0-9]+)/([^/]+) /index.php?page=subcateg&c=$1&cname=$2&s=$3&sname=$4&menu=sub [QSA]
RewriteRule ^subcateg/page/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+) /index.php?page=subcateg&c=$1&cname=$2&s=$3&sname=$4&pagenum=$5 [QSA]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [QSA]

RewriteRule ^$ index.php?page=home [QSA]

RewriteRule ^robots.txt$ robots.php [QSA]
Is it possible to simple redirect any URL that has "//" within it, to the error /selectpage ??
So whatever the page is, if that is in there, it will chuck them out.

Re: HTACCESS 301 - how do you point, when current URL has //

Posted: Thu Apr 09, 2015 10:55 am
by simonmlewis
Ok I am back on this problem again now.
I've pasted my HTACCESS code into that web site, all 2088 lines of it, put the URL at fault into it.

The URL in the file is highlighted and this is written:
RewriteRule ^subcateg/91/SERVICING-CENTRE/247/AEG-WORK//?$ index.php?page=selectpage [R=301,L]
This rule was met, the new url is http://www.site.co.uk/index.php?page=selectpage
Test are stopped, because of the R in your RewriteRule options. A redirect will be made with status code 301

Is this what should happen?
I'm pretty should it should be taking me to the "selectpage" file instead?!

Re: HTACCESS 301 - how do you point, when current URL has //

Posted: Thu Apr 09, 2015 11:03 am
by Celauran
Without additional context and assuming the URL in question is http://www.site.co.uk/subcateg/91/SERVI ... AEG-WORK//, yes, it absolutely looks like it's behaving as expected.

Re: HTACCESS 301 - how do you point, when current URL has //

Posted: Thu Apr 09, 2015 11:08 am
by simonmlewis
How then do I make it go from a 301 error page, to an actual inhouse page as requested in HTACCESS?
It's not behaving how I want it to. I'm saying... take that URL... to this URL.
It's saying... NO.

Re: HTACCESS 301 - how do you point, when current URL has //

Posted: Thu Apr 09, 2015 11:27 am
by Celauran
simonmlewis wrote:a 301 error page
A what? 301 is a redirect code (it's also a permanent redirect code, so you shouldn't be using it until things actually work). Please explain what's going on. Please provide the URI in question, the full .htaccess, the expected behaviour, and the actual behaviour.