homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Help for redirection

 6:05 am on Sep 2, 2011 (gmt 0)

I trying to redirect with following rule

RedirectMatch 301 (.*)/store/buy/travel-size/womens2011/TBG762 [test.co.uk...]

But it's not redirecting

Any Inputs please?




 7:27 am on Sep 2, 2011 (gmt 0)

Rule #1: Use "www.example.com" in any, er, example that's preceded by http:// All other domain names change into clickable links. This is fine in other forums, but here we need to see what you typed.

Does anything in your htaccess use mod_rewrite? If so, g1smd will be along shortly to tell you that you are taking your life into your hands when you mix mod_rewrite (Rewrite) and mod_alias (Redirect by that name) in a single htaccess file. Or config file or whatever you're in. You can use mod_rewrite to create redirects.

Meanwhile, we've got:
RedirectMatch 301 (.*)/store/buy/travel-size/womens2011/TBG762 http://www.example.com/store/bath-body/travel-size/womens2011/TBG884/

Oh, lord. For starters, you don't really need the http:// part unless you are redirecting to a different domain-- and your question gives no hint that this is the case. [httpd.apache.org...] * says
The new URL should be an absolute URL beginning with a scheme and hostname, but a URL-path beginning with a slash may also be used, in which case the scheme and hostname of the current server will be added.

I prefer not to give the full http business, because that makes it easier to distinguish at a glance between things that are being redirected to the same domain, and things that are going elsewhere.

Now then. How many different pages do you have whose url contains the sequence /store/buy/travel-size/womens2011/TBG762 ? Doesn't matter what comes after. How many different things can come before this part? We're not talking /images/ or /includes/ here; that's a pretty detailed series of directories.

The (.*) is fairly disastrous in any case, but here it also isn't necessary. Get as specific as you can.

* A bit further along, they give as an example
RedirectMatch (.*)\.gif$ http://www.anotherserver.com$1.jpg
I know who did not write this page of the documentation. Heh, heh.


 9:31 am on Sep 2, 2011 (gmt 0)

Whoever did, needs shooting.

Never use (.*) at the beginning or in the middle of a RegEx pattern.

"(.*)something" says "grab *everything* and put it in $1". After "everything" look for "something". This is garbage. Logically, there should be "nothing" after "everything". The parser then has to make thousands of back off and retry "trial match" attempts to find out what you really meant.

In real life someone asks you for directions to a building which you know (but they don't) is the only high-rise building in the road. The road is three miles long and the building is half way along it.

You tell them, "go to the very end of the road ignoring everything that you pass" (.*), and then "look for a high rise building after the end of the road" (something), and finally "back up if you can't see it". This means they will have to walk back a long way and take a lot longer.

What you should have said was "walk along the road ignoring all the low-rise buildings, then look at the high-rise building.

Use a different pattern.


 10:35 am on Sep 2, 2011 (gmt 0)

Thanks for you information.

I am new to apache redirection. Really your information will help me a lot.

My problem is

i simply used

Redirect 301 /store/buy/travel-size/womens2011/TBG762 [test.co.uk...]

it working if i remove /store. may be this rule was overwritten by some other rule.

The following are the rules related to store.

RewriteRule ^$ store [L]
RewriteRule ^/store/checkout/(.*)$ https://www.test.co.uk/store/checkout/$1 [R,L]
RewriteRule ^/store/myaccount/(.*)$ https://www.test.co.uk/store/myaccount/$1 [R,L]
RewriteRule ^/store/myacc/(.*)$ https://www.test.co.uk/store/myacc/$1 [R,L]

can you help me out please?

I have to learn apache webserver but this was in production..so not enough time to me to read all the document



 11:13 am on Sep 2, 2011 (gmt 0)

R gives a 302 redirect. You need 301 here.

Since you have used RewriteRule for some of your rules, you should use RewriteRule for all of your rules. [google.com...]


 1:34 am on Sep 3, 2011 (gmt 0)



actually exist? Is it a file or a directory? Is there more than one of it/them?

It sounds as if you want to redirect only this one specific address from /buy/ to /bath-body/ and also change the TBG number. Is that right?

In your RewriteRules, what's changing? Different subdomain? Different protocol? In your first post you had http; now you've got https. Something must be changing, since the whole rest of the path is repeated without change.

Incidentally, your three example rules can be collapsed into one:

RewriteRule ^/store/checkout/(.*)$ https://www.test.co.uk/store/checkout/$1 [R,L]
RewriteRule ^/store/myaccount/(.*)$ https://www.test.co.uk/store/myaccount/$1 [R,L]
RewriteRule ^/store/myacc/(.*)$ https://www.test.co.uk/store/myacc/$1 [R,L]

can be simply
RewriteRule ^(store/(myacc|checkout).+) https://www.test.co.uk/$1 [R=301,L]

That's assuming you don't have anything else that starts with "store/myacc" or "store/checkout". The ending anchor $ isn't needed, because RegEx is greedy by default and will carry on to the end unless you tell it not to. Are /myacc/ and /myaccount/ really different directories within /store/ ? That sounds perilous.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved