homepage Welcome to WebmasterWorld Guest from 54.161.197.188
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

    
Simple redirect - from one existing page to root
All I want is to redirect a some pages to the root. Can't figure it out...
InnerFlash




msg:3375530
 8:41 am on Jun 22, 2007 (gmt 0)

Hi all,

I feel very embarrassed about posting this thread, but the problem is so simple that I'm not finding an answer...

All I want is to redirect a page, let's say:

http://www.example.com/html/articles/index.php

to:

http://www.example.com/ (root)

I have to do it with several pages but haven't got it right after much trial and error. Something is missing from the syntax I'm using. Can someone help me with the right syntax for the simplest redirect problem in the whole universe?

Cheers,
Wallace

 

InnerFlash




msg:3375541
 8:55 am on Jun 22, 2007 (gmt 0)

PS: The pages I want to redirect from DO exist, but as their content is outdated, I want them to redirect to the root.

I have temporarily set up a custom "404 error" page (just save d the 404 page on the top of the old pages) that refreshes to the root, but I'd like to avoid that as search engines don't appreciate page refreshing.

Just to explain why I need it.

[edited by: InnerFlash at 8:57 am (utc) on June 22, 2007]

jdMorgan




msg:3375811
 2:48 pm on Jun 22, 2007 (gmt 0)

1) The RedirectMatch directive in Apache mod_alias is a good an fairly-simple one to use.

2) The overall plan is not good for search or for users. Search engines may see this as a "temporary doorway ploy ending in duplicate content" and users will be confused.

I'd suggest that you re-think this whole plan: For a few obsolete pages a year (like four pages), redirect them to new pages. For more than that where maintenance may become a problem, use a 410-Gone response, link the custom 410 page to your home page and to your category directory page(s), and possibly include a search function on the 410 page as well. Explain to the users with text (and to search engine spiders with the 410 response code) that the content has been intentionally removed, and try to help them get to a very-similar page.

Finally, if the content is popping in and out at a fast rate, then it might be a good idea to simply have one URL for "current news and events" or "current products" (or whatever is appropriate) and change the page content but not the URL. Search engines place little value on URLs that are constantly changing, and keeping up with your URL changes may distract them from spidering the rest of your site efficiently and tracking the resulting changes in PageRank/Link-pop "flow" through your site. Stable is much better.

Putting up 404 page content that replaces the previous page content is "wrong" and will cause you problems, as will using a meta-refresh. A 404 is a server response code sent to the client that tells it explicitly that the requested URL is missing for unknown reasons. It should not be used for any other purpose (Note that I recommend a 410 above). Straying too far from the mechanisms defined by the HTTP protocol for communicating with browsers and spiders is not the way to get best results.

Jim

InnerFlash




msg:3379105
 1:02 pm on Jun 26, 2007 (gmt 0)

Hi Jim,

Thanks for the thoughtful answer. To be honest I didn't understand the technical part of it, as I know practically nothing about apache and it's mod_rewrite, though I understand some of its purposes. I'm willing to learn and I will do my best, but right now there's pressure and I have to deliver...

Since I wrote last my "problem" has developed into something else, however I think that, in principle, I still need the same result.

The pages I want to get redirection for will stop existing as we are finally moving from one CMS to another. So I really need to get the old URLs redirected to new ones (at least the main categories of the shop).

All I need to know is the correct syntax for URL replacement. No advanced stuff, just a redirection from URL "A" to URL "B" with a 301 to make searching engines understand it's a permanent redirection.

I don't want to play with wild cards yet as it could prove daunting...

Cheers,
Wallace

InnerFlash




msg:3379116
 1:09 pm on Jun 26, 2007 (gmt 0)

Just another fast observation...

Changing the content of the pages instead of the URLs would be highly recommended in a static site, but it can be difficult in a dynamic one. But yes, appreciate the advice.

As we are moving from one CMS to another, there's no way we can replace the page content itself as the layout/URLs produced by the new CMS are completely different. The previous site didn't have SEF URLs, but the new one does.

[edited by: InnerFlash at 1:11 pm (utc) on June 26, 2007]

jdMorgan




msg:3379183
 2:34 pm on Jun 26, 2007 (gmt 0)

> Changing the content of the pages instead of the URLs would be highly recommended in a static site, but it can be difficult in a dynamic one.

Difficult is one thing, but losing your site's search rankings for six months to avoid that difficulty is another. You may have to decide between the two -- convenience versus revenue.

There are other issues beyond simply changing your URLs, and I'm trying to convey 'best practices' to encompass those other issues.

Notwithstanding, here's a simple example based on your example requirement posted above:

RedirectMatch 301 /html/articles/index.php http://www.example.com/

Study the Apache mod_alias documentation [httpd.apache.org] to avoid potentially-big problems, and check the server response for each page you redirect using a server headers checker such as the "Live HTTP Headers" extension for Firefox/Mozilla browsers. In response to a browser request for an old URL, you should see a single 301-Moved Permanently response, followed by a successful browser GET of the content from the new URL.

Jim

InnerFlash




msg:3381945
 10:32 am on Jun 29, 2007 (gmt 0)

Hi there!

Firstly I like to thank you, jdMorgan, for all the good advice you've given me so far - and your time!

I've had big difficulties to apply the changes you've recommended, because the server support hasn't given me any feedback on the installation of the module "mod_alias" on the apache server I requested.

To make it short, your solution did not work for me.

Searching a lot through forums over the web, I tried to do something else, which worked in one way, but not the one i intended. I need it to be like this:

Redirect /index?c0=133&cat_id=133&level=1 [mydomain.com...]

and that didn't work... so when I tried the opposite way, just to find out if it would work, it DID work:

Redirect /page.html [mydomain.com...]

As you can see the old URL is created dynamically and doesn't have a file extension to it. I wonder if that's the reason the first redirecting didn't work?

InnerFlash




msg:3382142
 3:08 pm on Jun 29, 2007 (gmt 0)

Isn't..

RewriteRule ^index?c0=142&cat_id=142&level=1$ /page.html [L,R=301]

...supposed to work?

I really don't get it. I'm doing my best to try to understand how to do it, but the urgency of having this job done is much greater than what my learning curve allows. The shop is going live TONIGHT, 29th June and this deadline can't be pushed further.

Please, if there's someone out there who knows the correct redirect syntax to a specific non-existing dynamic URL (my old dynamic URLs will become obsolete tonight) to specific existing static URLs, please do post... the non-existing dynamic URL request will be only external.

I need an URL like this:

http://www.example.com/index?c0=142&cat_id=142&level=1

to become like this:

http://www.example.com/page1.html

I have several URLs that need the same redirection, but they are all very similar to the URL above, only with different category numbers. So one solution will cover all the others.

This I'll have to do with (or without) "mod_rewrite", but not with "mod_alias" as i don't have it installed on my server.

The purpose here is to redirect old categories from the old shop to new categories with the same name in the new shop.

Really appreciate any input!
Cheers

jdMorgan




msg:3382350
 5:59 pm on Jun 29, 2007 (gmt 0)

> This I'll have to do with (or without) "mod_rewrite", but not with "mod_alias" as i don't have it installed on my server.

Actually, you do, since you reported that the Redirect directive worked on your server --if not exactly the way you wanted it to-- and Redirect is implemented by mod_alias, as described in the mod_alias documentation.

> I have several URLs that need the same redirection, but they are all very similar to the URL above,
> only with different category numbers. So one solution will cover all the others.

Not necessarily: You may need to define how the category numbers can vary within the group of URL+query string combinations you *do* wish to redirect, and whether any other similar URL+query strings exist that you *don't* want to redirect.

Isn't..
RewriteRule ^index?c0=142&cat_id=142&level=1$ /page.html [L,R=301]
...supposed to work?

No, it's not. The basic problem you've got (along with others who try to do this) is that query strings are not part of a URL -- They are data *attached* to a URL, and mean absolutely nothing to Apache itself. Therefore, simple redirects as implemented in mod_alias and mod_rewrite are not 'aware' of query strings, and do not comprehend them in any way. Therefore, these redirects cannot be made to be conditional upon query strings while remaining simple...

This will redirect /index?c0=142&cat_id=<cat_string>&level=1$ to /page<cat_string>.html, with the value of <cat_string> copied from the requested URL to the new URL, while the "page" URL and the "c0" and "level" parameter values are presumed to be fixed (unchanging) values:

RewriteCond %{QUERY_STRING} ^c0=142&cat_id=([^&]+)&level=1$
Redirect ^index$ http://www.example.com/page%1.html? [R=301,L]

Not sure if that's exactly what you want, but you can adjust it to suit.

Jim

InnerFlash




msg:3395607
 8:03 am on Jul 16, 2007 (gmt 0)

Hi again Jim,

It's been always a challenge for me to get my need across public forums, and I guess the nature of this kind of communication can certainly take some of the blame...

We left this problem aside for a while as we had other pressing issues to solve, but now we're back to it. I have looked for solutions simultaneously in various forums, but your expertise has excelled all the other replies we've got.

However, I realize now I haven't been able to explain the problem accurately. If you have the time to answer we would appreciate it a lot...

The URLs that need to be replaced are all obsolete. They're gone as we have moved from one system to another. So the matter of dynamic queries does not arise, since the old system is down and no query will be dynamically generated. That leaves us with "static" URLs existing only as external referrals and bookmarks. The only thing that remained the same is the domain name.

Our only concern now is to reclaim the PR and traffic from those obsolete URLs by permanently redirecting them. When I said they were similar, I meant something like this:

/index?c0=515&cat_id=515&level=1
/index?c0=156&cat_id=156&level=1
/index?c0=139&cat_id=139&level=1
/index?c0=133&cat_id=133&level=1
...

These used to be links to main categories in the old system, that we would like to forward to much friendlier URLs in the new system, like:

/buckles.html
/belts.html
/shirts.html
/shoes.html
...

In this context, the solution you proposed last can't be applied, as the pages "once dynamic but now obsolete" are being forwarded to dynamic pages that have their names changed to the category name and appear to be static. The number of categories are completely different and there isn't a possible connection there.

Since the old URLs are no longer going to be dynamically changed - and are going to be redirected to static URLs, I wonder if there is a way to do something similar to this:

RewriteCond ^c0=142&cat_id=142&level=1$
Redirect ^index$ http://www.example.com/buckles.html? [R=301,L]

As you see, I need to define the numbers that used to be dynamic so I can redirect it to where it should point to.

I hope you have the patience and the time to help me once again... :(

InnerFlash




msg:3395626
 8:47 am on Jul 16, 2007 (gmt 0)

Would something like this do the trick?

RewriteCond %{QUERY_STRING}!^c0=139&cat_id=139&level=1$ [NC]
Redirect ^index$ http://www.example.com/belts.html [R=301,L]

I don't need the interrogation point in the end of the "redirected to" URL, do I?

jdMorgan




msg:3395903
 3:36 pm on Jul 16, 2007 (gmt 0)

> I don't need the interrogation point in the end of the "redirected to" URL, do I?

You most certainly do. It is an operator which clears the current query string. If you omit it, then the old query string will be attached to the new URL by default. I wouldn't have bothered to type it were it not needed. This "?" will not appear in the redirect URL.

Restore that "?" and remove the NOT operator from the RewriteCond pattern:

RewriteCond %{QUERY_STRING} [b]^c0[/b]=139&cat_id=139&level=1$ [NC]
Redirect ^index$ http://www.example.com/belts.ht[b]ml?[/b] [R=301,L]

Jim

InnerFlash




msg:3397846
 7:24 am on Jul 18, 2007 (gmt 0)

Hi again Jim,

Man, I really do appreciate your help so much, you can't imagine. Thank you.

I'm looking forward to the day I'll come back here and say YES! It's working! But it won't be this time...

Funny, because after so much trial and error, this thing is almost making sense to me. I've read some of the documentation on mod_rewrite too, and frankly don't understand why your suggestion didn't work. My .htaccess is not particularly big, so I don't believe there's anything conflicting there. But it could happen, isn't it? Does .htaccess behave in the same way a CSS does, meaning, it cascades and cancel the previous code as it's read?

I can't seem to puzzle out the problem. Perhaps "index" is seen as part of the query string in this URL?

http://www.example.com/index?c0=139&cat_id=139&level=1

It isn't the usual "index.php?" we usually would see in these situations...

I'm sorry to bother you again with it, but I really don't know where to go to for help. If you have the time and patience to ponder on it, it would be great.

Cheers!

phranque




msg:3397883
 7:49 am on Jul 18, 2007 (gmt 0)

Does .htaccess behave in the same way a CSS does, meaning, it cascades and cancel the previous code as it's read?

it is difficult to generalize about the order of processing for rewrite directives.

I can't seem to puzzle out the problem. Perhaps "index" is seen as part of the query string in this URL?

http://www.example.com/index?c0=139&cat_id=139&level=1

the query string always starts with the "?".

what is the response you get using the latest suggested directives?
any clues in the server logs perhaps?

InnerFlash




msg:3397907
 8:28 am on Jul 18, 2007 (gmt 0)

the query string always starts with the "?".

I thought that was so, but since the last suggestion Jim gave didn't work, I started to wonder...

what is the response you get using the latest suggested directives?

When I type in the url:

http://www.example.com/index?c0=139&cat_id=139&level=1

I go to the "Home" page instead of the

http://www.example.com/belts.html

The url "http://www.example.com/index?c0=139&cat_id=139&level=1" keeps showing on the address bar, and I can see the pagerank that URL still has... :'(

any clues in the server logs perhaps?

The error log shows no other errors connected with these urls, only that the favicon.ico was not found because is not on its old location. I suppose it would have to stand "non-existing URL", but as Jim said earlier, the "c0=139&cat_id=139&level=1" part of the URL is only a query string and not seen as a URL at all.

The access log shows me many hits on the old URLs.

InnerFlash




msg:3397913
 8:33 am on Jul 18, 2007 (gmt 0)

I have tried to place a page on another domain with a link to

http://www.example.com/index?c0=139&cat_id=139&level=1

to get a completely external incoming link request, but it didn't work either.

I've placed a page inside my domain linking to

index?c0=139&cat_id=139&level=1

to get a completely internal link request, but it didn't work as well.

I get only the "Home" page showing, as described above.

[edited by: InnerFlash at 8:36 am (utc) on July 18, 2007]

phranque




msg:3397956
 10:09 am on Jul 18, 2007 (gmt 0)

have you tried clearing your browser cache?

InnerFlash




msg:3397998
 11:43 am on Jul 18, 2007 (gmt 0)

The problem was that the Redirect wasn't being used correctly. Firstly I was using a regexp (Óndex$) in the URL path to Redirect. That doesn't work. One can only use regexp with RedirectMatch. See [httpd.apache.org...] for more info. It's not clear for me if RewriteCond can be used together with Redirect or RedirectMatch... I have never seen them together.

Redirect ^index$ http://www.example.com/belts.html? [R=301,L]

The code above was supposed to redirect everything that begins with index to http://www.example.com/belts.html. However, since it's not possible to use [ ^index$ ] in Redirect, it didn't work.

So, this doesn't work:
RewriteCond %{QUERY_STRING} ^c0=139&cat_id=139&level=1$ [NC]
Redirect ^index$ http://www.example.com/belts.html? [R=301,L]

This does work:
RewriteCond %{QUERY_STRING} ^c0=139&cat_id=139&level=1$ [NC]
RewriteRule ^index(.*)$ http://www.example.com/belts.html? [R=301,L]

I found out as well that if you have made a rewrite early in the .htaccess, the ones following will not work, even while stating a different rule or condition for the same variable. So it does not cascade like with CSS, but the opposite.

I thank everyone for their time and effort, specially Jim who put so much thought into this.

Thanks again!
Wallace

[edited by: InnerFlash at 11:46 am (utc) on July 18, 2007]

g1smd




msg:3398088
 1:48 pm on Jul 18, 2007 (gmt 0)

You can chain one rule on to the next in some circumstances, but it can get very complex.

Most of it is beyond me too.

jdMorgan




msg:3398114
 2:08 pm on Jul 18, 2007 (gmt 0)

> I have never seen them together.

Neither have I, until now. But unfortunately, I utterly failed to notice that you were trying to use "Redirect"!

RewriteCond and Redirect are supported by different modules -- mod_rewrite and mod_alias, and will NOT work together.

Jim

[edited by: jdMorgan at 2:09 pm (utc) on July 18, 2007]

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