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

RedirectPermanent problem
need help directing a batch of urls

 10:33 pm on Mar 23, 2013 (gmt 0)

Hi all,
I hope someone can help

I need to do redirects for a series of dynamic urls to the root domain.

RedirectPermanent /?attachment_id=100 /index.php

is not functioning for this uneducated in the ways of .htaccess person.

My goal is to redirect a list of about 20 different id=xxx

urls to the root URL, but i'll start with just one
should be routed to

thanks for any help



 11:14 pm on Mar 23, 2013 (gmt 0)

point of information, if it will help for a possible different aproach.
all of the above urls are 404 errors.
if I DO redirect all to the root - will it
cause duplicate pages?


 11:27 pm on Mar 23, 2013 (gmt 0)

Technically it isn't duplicate content, since there is only one root page. But g### doesn't much like mass-redirects.

When you say "404 errors" do you mean that they are showing up on the gwt error list? Where are these bad URLs coming from? Make sure there are no typos anywhere on your own site.

Redirecting from a page with parameter to the same URL without parameter is probably not the optimal way to go in any case. It is better to backtrack a little and explain about the attachment_id parameter.

If it has no meaning at all, then tell gwt to ignore it.

If it has meaning only some of the time, then a 404 response is correct for the ones that don't lead to a page.

If some values of attachment_id used to exist but no longer do, then the php page should probably return a 410 instead.


 12:30 am on Mar 24, 2013 (gmt 0)

Redirects should always include the canonical hostname in the rule target. To omit it, invites various problems.

Never redirect to an "index" URL. The canonical URL for a folder or for the index page in a folder ends with a trailing slash.

Forget that Redirect and Redirectmatch ever existed. They both have very limited functionality. In particular they cannot "detect" appended parameters. They can match only the path part of the URL request, and any requested parameters are merely re-appended to the target URL within the redirect process.

Learn about RewriteCond and RewriteRule. These offer a lot more functionality.

It's usually not appropriate to mass redirect multiple URLs to a single URL and especially to not redirect to the root of a site. Some other solution might be called for.


 3:12 am on Mar 24, 2013 (gmt 0)

thanks folks, much to chew on...
will post what happened :-)


 3:28 am on Mar 24, 2013 (gmt 0)

[If some values of attachment_id used to exist but no longer do, then the php page should probably return a 410 instead.]

THAT IS exactly the situation.
How do I accomplish a 410?


 5:03 am on Mar 24, 2013 (gmt 0)

How do I accomplish a 410?

It depends how many there are. A 410 never happens automatically like 403 or 404; you have to code for it. The two basic ways are:

-- In mod_rewrite with a RewriteCond looking at the %{QUERY_STRING}. You cannot do it in mod_alias (Redirect by that name). In your first post you said there are about 20 pages. That's kind of a lot, though still possible. But it can get very messy if the query string contains elements other than attachment_id and you need to keep those elements.

-- In the same php program that generates the page. If you have some values of attachment_id that are still used by your php, then this seems like a much simpler way to do it. Simply give your php page a list of no-longer-valid values and let it spit out a 410 if any of those are used. This, again, is assuming that there will be nothing else in the query string.

To go with the 410 response, you should make a nice custom 410 page. You can even make different 410 pages for different situations. But it has to be done as an ErrorDocument; don't redirect those 20 pages to the root.

I am not going to tell you how to do it in php, for two reasons. One reason is that this is the Apache forum and we don't write code for you. But we'll help you along if you do it yourself. The other reason is that I don't speak php and would certainly get it wrong myself ;)

:: wandering off to php dot net to see what's involved ::

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