Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite in .htaccess unexpected results

Can't figure out the syntax for what I really want

         

SpyMaster

6:40 pm on Nov 21, 2006 (gmt 0)

10+ Year Member



Hello, this is my first post. I've beat my head against the Apache documentation for 5 hours, looked everywhere for examples, and searched here. I hope someone will take pity on me.

My old directory structure looked like this:

index.php (a file)
this.php (a file)
that.php (a file)
the_other.php (a file)
/linkable_images (a directory)

My new structure looks like this:

index.php (a file)
this.php (a file)
that.php (a file)
the_other.php (a file)
/linkable_images (a directory)
/my_new_wordpress_site (a directory)

The goal here is that all of the old top-level files no longer matter, and all requests for them go into /my_new_wordpress_site BUT that requests for resources in /linkable_images still be accesbile.

I managed to get the redirection to /my_new_wordpress_site to work using the following, but unfortunately ALL requests go into /my_new_wordpress_site and thus my /linkable_images images aren't, well, linkable anymore...

RewriteEngine On
RewriteBase /
RewriteRule ^(.*) http://www.example.com/my_new_wordpress_site [R=301]

Can anyone explain how to do what I'm trying to do and provide a working example, please?

[edited by: jdMorgan at 7:01 pm (utc) on Nov. 21, 2006]

jdMorgan

6:58 pm on Nov 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add a RewriteCond to make the rule conditional. Either:

RewriteCond $1 !^linkable_images
RewriteRule (.*) http://www.example.com/my_new_wordpress_site [R=301,L]

-or-

RewriteCond %{REQUEST_URI} ![b]^/l[/b]inkable_images
RewriteRule (.*) http://www.example.com/my_new_wordpress_site [R=301,L]

However, it's doubtful that you really want search engines to drop all URLs on your site but http://www.example.com/my_new_wordpress_site. If you want to retain the appearance of the site actually residing at at your domain root, use a rewrite, not a redirect:

RewriteCond $1 !^linkable_images
RewriteRule (.*) /my_new_wordpress_site [L]

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

[edited by: jdMorgan at 7:00 pm (utc) on Nov. 21, 2006]