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

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:

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

Post 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]
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: HTACCESS 301 - how do you point, when current URL has //

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

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

Post 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.
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: HTACCESS 301 - how do you point, when current URL has //

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

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

Post by simonmlewis »

Fair enough. but it won't work at all, because of the //.
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: HTACCESS 301 - how do you point, when current URL has //

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

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

Post 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.
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: HTACCESS 301 - how do you point, when current URL has //

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

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

Post 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.
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: HTACCESS 301 - how do you point, when current URL has //

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

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

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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?!
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: HTACCESS 301 - how do you point, when current URL has //

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

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

Post 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.
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: HTACCESS 301 - how do you point, when current URL has //

Post 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.
Post Reply