Forum Moderators: phranque

Message Too Old, No Replies

help with a custom redirect

htaccess redirect

         

thedark1

4:20 pm on Feb 14, 2009 (gmt 0)

10+ Year Member



hi,

Im archiving a dot com domain to a dot net. But the thing is that many people have bookmarked pages for the dot com domain.

so i want an htacess which does this:

if the url is not found (404) then redirect to the same url but on the dot net domain eg:

if

http://example.com/showthis.php?type=1&id=35603 = 404 error

then redirect to

http://example.net/showthis.php?type=1&id=35603

can anyone tell me what the htacess for this should be?

thanks

jdMorgan

4:24 pm on Feb 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post your best-effort code as a basis for discussion.

Thanks,
Jim

thedark1

4:49 pm on Feb 14, 2009 (gmt 0)

10+ Year Member



um, i'm totally clueless here as far as best effort is concerned, i mean I know a redirect from one domain to another is easy, but how are we supposed to insert a 404 condition to that?

jdMorgan

5:21 pm on Feb 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the "showthis.php" script file will always exist, you'll need to modify that script to detect "missing pages."

Mod_rewrite cannot know that the database entry for "type=1&id=35603" does not exist, because mod_rewrite has no knowledge of your CMS or database.

If the question is "How do I detect if the file corresponding to the URL-path '/showthis.php' does not exist?", then the answer is to use a RewriteCond checking %{REQUEST_FILENAME} and the "-f" operator, as described in the mod_rewrite documentation.

Please see our Apache Forum Charter [webmasterworld.com] for links to useful information and tips for getting the most from this forum.

Jim

[edited by: jdMorgan at 5:57 pm (utc) on Feb. 14, 2009]

thedark1

5:50 pm on Feb 14, 2009 (gmt 0)

10+ Year Member



ok, thanks for the info