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

Apache Web Server Forum

    
.htaccess Redirect if File Does Not Exist
brokenbynubs




msg:4189471
 9:17 pm on Aug 19, 2010 (gmt 0)

I have a group of files something like this:

example.com/test-1234.html
example.com/test-5678.html
example.com/test-9101.html
example.com/test-1213.html
example.com/test-1415.html

Some exist, some don't... I'm trying to set up a redirect so the ones that don't exist are sent to my search page and the ones that do exist aren't modified at all. I've got this semi-working, except it sends the user to my live directory(www.example.com) instead of my development directory(dev.example.com):

#RewriteCond %{REQUEST_FILENAME} !-f
#RedirectMatch /test-(.*).html search.example.com/search/test-$1 [R=301]

So my question is, is there a better way to do this? If not, how do I make it stay on the development directory and not send me to the live one?

 

g1smd




msg:4189473
 9:25 pm on Aug 19, 2010 (gmt 0)

For the ones that don't exist, send a 404 response and present a search box on the 404 error message page.

Redirecting to another URL is not the correct action for the pages that do not exist.

brokenbynubs




msg:4189568
 2:53 am on Aug 20, 2010 (gmt 0)

That isn't a feasible option for me. I have thousands and thousands of pages linked within the site that would take too many man hours to fix. Redirecting to our search is the best option for us at this time.
Most of the pages that don't exist anymore are because they were renamed and our learning search will find them as well as show the related pages.

jdMorgan




msg:4189570
 3:11 am on Aug 20, 2010 (gmt 0)

The closest you can get to technically-correct with a redirect would be:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^test-([^.])+\.html http://dev.example.com/search/test-$1 [R=302,L]

I show a 302 redirect, because a 301 would be "SEO suicide."

A *much* better solution if you care about search engine rankings would be to use the default 404 response for those non-existent pages, and to either #include the search function on the custom 404 error page, or to use the search page itself as the custom 404 error page:

ErrorDocument 404 /search.php

However, the "search.php" script will now have to get the originally-requested URI from the REQUEST_URI server variable, as that information is no longer being passed to it by a rewrite or redirect.

Because the server status response with this configuration is a 404-Not Found, you avoid trouble with search engines detecting an "infinite URL-space" or flagging massive duplicate-content on your site, and users see a nice search-facility page with no jarring NOT FOUND messages... Best of both worlds.

Jim

javigh123




msg:4197995
 8:22 pm on Sep 7, 2010 (gmt 0)

I have a Wordpress Multisite website and i want any url that does not exist to redirect to my main website.

for example, if mysite.com/test does not exist i want it to redirect to myofficialsite.com

I don't care for SEO on this website.

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