Forum Moderators: phranque

Message Too Old, No Replies

redirect everything but one file

using redirect 301 and .htaccess

         

simone

9:53 pm on Sep 1, 2009 (gmt 0)

10+ Year Member



Hi everybody.

I have a second level domain (www) example.com redirecting to a
third level domain blog.example.com by "redirect 301".

I'd like it worked for every query of (www) example.com but one file, for
example (www) example.com/minisite_1.html

How can i do that ? How about adding a second file, say example.com/minisito_2.html, to be excluded from "redirect 301" to blog.example.com ?

sorry for my English.

Thanks in advance,
Simon from Italy

[edited by: jdMorgan at 10:11 pm (utc) on Sep. 1, 2009]
[edit reason] Please use example.com [/edit]

jdMorgan

12:31 am on Sep 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you really want to use the filename as a condition, you can enclose the Redirect directive in a <Files> container -- See Apache core, <Files> [httpd.apache.org] and <FilesMatch> directives.

You could also use mod_rewite, and use one or more RewriteConds to exclude one or more requested files or URL-paths (or many other request characteristics) from being redirected.

Jim

simone

7:55 pm on Sep 3, 2009 (gmt 0)

10+ Year Member



Well, all i know is using the filename as a condition and some mod_rewrite rules (RewriteConds).

Is there any better condition to use ?

Thanks,
Simon

jdMorgan

12:47 pm on Sep 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Example using mod_rewrite in .htaccess

RewriteCond $1 !^minisite_1\.html$
RewriteCond $1 !^minisite_2\.html$
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule ^(.*)$ http://blog.example.com/$1 [R=301,L]

You will likely also want to exclude any images, CSS or JS files, or media objects loaded by the "minisite.html" pages from being redirected.

You can combine the first two RewriteConds into one if you like, but using the "local OR" operator:


RewriteCond $1 !^(minisite_1¦minisite_2)\.html$

Replace the broken pipe "¦" character with a solid pipe character before use; Posting on this forum modifies the pipe character.

Jim