Welcome to WebmasterWorld Guest from 54.226.246.160

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

.htaccess Redirect if File Does Not Exist

     

brokenbynubs

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

5+ Year Member



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

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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

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

5+ Year Member



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

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month