htaccess Redirect Scenario, featuring WordPress

I’m no good at anything that requires regular expressions – this includes redirects.

I need to redirect all subpages to a particular subpage. Everything I’ve tried either fails or causes an infinite redirect loop.

Read More

Example: Say I want everything under the domain to redirect to www.test.com/fubar (but obviously not /fubar)

This seems like it should be super easy. Anyone?

[Update]

I’ve tried everything posted so far, and nothing works. What’s happening is that the pages are not redirecting and also not loading stylesheets. I think it has something to do with the rest of the htaccess file, which contains stuff for WordPress:

RewriteEngine On

RewriteBase /

#uploaded files
RewriteRule ^(.*/)?files/$ index.php [L]
RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
RewriteRule ^(.*/)?files/(.*) wp-content/blogs.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} ^.*/wp-admin$
RewriteRule ^(.+)$ $1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [L]
RewriteRule . index.php [L]

Related posts

Leave a Reply

4 comments

  1. I’d say something like this:

    # Don't rewrite anything in /fubar
    RewriteRule ^fubar - [L]
    # Redirect everything to /fubar
    RewriteRule ^(.*)$ /fubar/$1 [R=301,L,QSA]
    
  2. What you want:

    
    RewriteEngine On
    RewriteRule ^fubar/ - [L] // protect from loop, not sure if its really necessary
    RewriteRule ^.*$ fubar/$0 [L,QSA]
    

    Now to redirect only if the file path as given from the user does not exist:

    
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^.*$ fubar/$0 [L,QSA]
    
  3. This is easier to do using proxies:

    ProxyRequests Off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyPass / http://www.test.com/fubar/
    ProxyPassReverse / http://www.test.com/fubar/