Forum Moderators: phranque

Message Too Old, No Replies

rewriterule on htaccess problem

How to redirect all url that include virtuemart phrase

         

Racc00n

5:02 am on Sep 20, 2012 (gmt 0)

10+ Year Member



Hi!

I want to redirect all my url that include "virtuemart" phrase to my domain root.

When searhing the net I find out that my line should look something like this.

RewriteEngine On
RewriteCond %{QUERY_STRING} virtuemart=(.*)
RewriteRule ^grab(.*) /etusivu

where the virtuemart url would be redirected to www.mydomain.com/etusivu

But when I add that line to the htaccess file it won't work.

could someone help me to fix it!

thanks

lucy24

5:25 am on Sep 20, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is "virtuemart" in the query string or in the body of the URL?

There are other problems, but let's start with that. Oh, and go read the post about using example.com. The thread is right next to this one.

phranque

5:34 am on Sep 20, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, Racc00n!

IMPORTANT: Please Use Example.com For Domain Names in Posts - Apache Web Server forum at WebmasterWorld:
http://www.webmasterworld.com/apache/4452736.htm [webmasterworld.com]

it won't work

the best way to get your problem solved is to describe the request and the response.

the RewriteRule you used will do an internal rewrite.
if you want a redirect you should specify the R flag.

also if you are doing a redirect you should specify the protocol and hostname in the target.

i would also question if you really want to redirect a potentially large number of urls to one url.
that rule will apply to any url that has a path starting with "grab" and a query string containing "virtuemart=".

g1smd

5:46 am on Sep 20, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Rule order is also important. You can't just drop new rules anywhere in the file and hope they work.

Remove both (.*) parts.
Add the protocol and domain to the rule target.
This is a redirect? Tell it. Add [R=301,L] flags.
You'll also need to strip the query string, so add a question mark to the end of the rule target.

Racc00n

10:13 am on Sep 20, 2012 (gmt 0)

10+ Year Member



Hi!

Thanks for all of your replies and sorry for giving only little info on the first post.

So my problem is that I have changed ecommerce system. I earlier had virtuemart and now lots of links that I have on google (and elsewhere on the internet) point to those old url’s and users get 404 error pages when they use those url’s.

So I wish that when someone try to come my site using those old url’s they should be moved to my domain root instead giving them 404 error page.

When I try that code that I put on the first message nothing happens. URL’s still go to 404 error page.

Here are answers to some of your questions.

Q: Is "virtuemart" in the query string or in the body of the URL?
A: If I get right what query string means then it is in query sting.

Q: it won’t work
A: hopefully text above this has allready answered to this.

And q1smd thanks for the tips.

You said that add protocol rule. Could you help with it little bit more as I don’t have any idea what you mean by that ”protocol”

I did try to make the other changes you said. Does the text below look the way you ment it?

RewriteEngine On
RewriteCond %{QUERY_STRING} virtuemart
RewriteRule ^grab http://www.example.com [R=301,L]?

g1smd

6:32 pm on Sep 20, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Protocol is the "http://" part of the URL.

Domain root usually ends with a trailing slash. Adding a question mark supresses parameters.

Howver, it's usually bad form to mass redirect multiple URLs to a single URL and especially to the domain root.

For pages that have "gone" you should be returning a custom 404 or 410 page explaining to the visitor exactly what has happened.

lucy24

1:44 am on Sep 21, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If I get right what query string means then it is in query string.

Uhm. I think what we were hoping for was an unequivocal "Yes it is in the query string" or "No it is in the body of the URL".

www.example.com/directory/morestuffhere?virtuemart=something

OR

www.example.com/directory/virtuemart/morestuffhere

?

It helps a lot if you can give a few examples of what you are trying to do. Remember to replace your domain name with example.com (or .co.uk or whatever it is, so long as the middle is "example").

Go ahead and put it in baby talk. "When people type in such-and-such, I want to send them to this-and-that." Or "When people use an old bookmark that says such-and-such, I want them to end up at such-and-such." Or "I want the browser's address bar to say such-and-such, but I want people to see a page that really lives at here-and-there."

Racc00n

6:37 am on Sep 21, 2012 (gmt 0)

10+ Year Member



Hi!

URL that I would like to redirect is something like this:

http://www.example.com/index.php?page=shop.product_details&flypage=flypage.tpl&product_id=76&category_id=98&option=com_virtuemart&Itemid=99

and I would like that customers who use that address would end to this page.

http://www.example.com

Hopefully this cleared what I hope to achieve.

kind regards

g1smd

7:30 am on Sep 21, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Changing the slash and the question mark as I mentioned above should fix the code you supplied immediately above my comment.

lucy24

10:00 am on Sep 21, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



http://www.example.com/index.php?page=shop.product_details&flypage=flypage.tpl&product_id=76&category_id=98&option=com_virtuemart&Itemid=99

and I would like that customers who use that address would end to this page.

http://www.example.com

Well, they are on that page, even if they're seeing something else. Do you mean that you want to throw away the whole query string if it contains the element "virtuemart" anywhere in it? Can the same query show up in requests for other pages too?

If not, you're barely even redirecting:

RewriteCond %{QUERY_STRING} virtuemart
RewriteRule ^(index\.php)?$ /? [R=301]

The (index\.php)? there is not formally necessary. You could say (.*) and end up in the same place. But your server shouldn't have to stop and look at the Condition every time it gets any request for any file whatsoever-- including things like images that would never have a query in the first place.

Racc00n

12:37 pm on Sep 21, 2012 (gmt 0)

10+ Year Member



Do you mean that you want to throw away the whole query string if it contains the element "virtuemart" anywhere in it?

Yes

Can the same query show up in requests for other pages too?
Yes, there is about 1000 url's that include that virtuemart phrase but all of those are at the moment giving 404 error.

I did change my ecommerce system and that is why those virtuemart url's are now showing on webmaster tools as indexing errors.

Thanks for your help with this.
I will try those in the weekend and hopefully I get them working.

phranque

6:05 pm on Sep 21, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



redirecting those 1000 urls to the home page will not work out well - it will probably be reported as a GWT error - and it is a poor user experience.

lucy24

8:17 pm on Sep 21, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You could add a RewriteCond so if the requested page is anything other than the top-level Index, serve a 410 instead. It should make g### give up a little faster than the current diet of 404s.

Do those 1000+ URLs have anything in common? That is, in the body of the URL, not the query string. Anything you can put in the Rule itself so the server doesn't have to check every single page request every time.

Do the pages exist at all? What happens if you request the page without a query string? Or with a query string that doesn't contain the "virtuemart" element?