301 Redirect going to Long URL - why?

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

jdhmtl
Forum Newbie
Posts: 18
Joined: Tue Aug 12, 2014 7:33 am

Re: 301 Redirect going to Long URL - why?

Post by jdhmtl »

Both rewrite conditions need to be met in order for the rule to be applied. The first checks the page requested, the second checks the query string (?url=etc) and then the redirect triggers when both are met. You can add regex into the second condition to make it apply to a group of query strings rather than a specific one if need be.
jdhmtl
Forum Newbie
Posts: 18
Joined: Tue Aug 12, 2014 7:33 am

Re: 301 Redirect going to Long URL - why?

Post by jdhmtl »

You may also find htaccess tester to be useful.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: 301 Redirect going to Long URL - why?

Post by simonmlewis »

Iv'e got over 600 of these to do.

Can it be done like this?

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/?$
RewriteCond %{QUERY_STRING} ^url=http://www.site.co.uk/product/242/HOLD/312/HOLD/372/R9-P90S/?$
RewriteCond %{QUERY_STRING} ^url=http://www.site.co.uk/product/335/HOLD/312/HOLD/372/R9-P90S/?$
RewriteCond %{QUERY_STRING} ^url=http://www.site.co.uk/product/664/HOLD/312/HOLD/372/R9-P90S/?$
RewriteCond %{QUERY_STRING} ^url=http://www.site.co.uk/product/666/HOLD/312/HOLD/372/R9-P90S/?$
RewriteRule (.*)  index.php?page=selectpage&menu=home [L]
So I can use Excel to strip back the URL and get it done way faster, or do you literally have to do it three rows at a time??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
jdhmtl
Forum Newbie
Posts: 18
Joined: Tue Aug 12, 2014 7:33 am

Re: 301 Redirect going to Long URL - why?

Post by jdhmtl »

That's definitely not going to work as all rewrite conditions must pass before the rewrite rule fires. Why not use regex instead of copying 600 lines?
jdhmtl
Forum Newbie
Posts: 18
Joined: Tue Aug 12, 2014 7:33 am

Re: 301 Redirect going to Long URL - why?

Post by jdhmtl »

Something like this should do what you need. Swap out regex patterns for static values if/as needed.

Code: Select all

RewriteCond %{REQUEST_URI} ip_mobilehome.php
RewriteCond %{QUERY_STRING} ^url=http://www.site.co.uk/product/[\d]{3}/HOLD/[\d]{3}/HOLD/[\d]{3}/R9-P90S/?$
RewriteRule (.*)  index.php?page=selectpage&menu=home [L]
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: 301 Redirect going to Long URL - why?

Post by simonmlewis »

[text]/subcateg//CLEARANCE-SALE//CLOTHING/[/text]
We are getting "NOT FOUND" errors for these URLs, quite rightly, because there are missing numbers in there.

It seems to be caching old links that were wrong, but have since left the web site, but as they are cached, they still error on the Google Webmasters.

So how do I do one of these for that?

Code: Select all

RewriteRule ^subcateg//CLEARANCE-SALE//CLOTHING/?$  /subcateg/56/CLEARANCE-SALE/66/CLOTHING [QSA]
It doesn't like // in the rule.
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: 301 Redirect going to Long URL - why?

Post by Celauran »

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

Re: 301 Redirect going to Long URL - why?

Post by simonmlewis »

Code: Select all

RewriteRule ^subcateg\/\/CLEARANCE-SALE\/\/CLOTHING/?$  /subcateg/56/CLEARANCE-SALE/66/CLOTHING [QSA]
Like this you mean?
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: 301 Redirect going to Long URL - why?

Post by simonmlewis »

Also, if I want to permanently tell googlebots that a URL is now *this* URL, is it best done in the way I have written it, or like this:

Code: Select all

RewriteRule ^/subcateg/4/TACTICAL-FIGURE-SETS-1:6/22/FBI-FIGURES/?$  /subcateg/4/TACTICAL-FIGURE-SETS-1:6/224/FBI-FIGURES/ [R=301,L]
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply