Let me redirect

  • www.example.com/* to example.com/*

And simultaneously redirect

  • example.com/* to example.com/forum/*

However I also provide /wiki/ and /blog/ and /style/, and so i do not want to redirect

  • example.com/style/* to example.com/forum/style/*

This is exactly what I've right now, which isn't working quite properly:

Options +FollowSymLinks
RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/forum/
RewriteRule ^(.*)$ forum/$1 [R=301,L]

Clarification: my question could be requested inside a simpler way.

Let me redirect an *empty REQUEST_URI* or /, or perhaps a non-existent file only when it is incorporated in the root directory to /forum/.

Do this:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://example.com/$1 [R=301,QSA,L]

RewriteCond %{REQUEST_URI} !^/(wiki|blog|style|forum)
RewriteRule ^(.*)$ http://www.example.com/forum/$1 [R=301,QSA,L]

I'd begin using these rules:

# redirect www.example.com to example.com
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^ http://example.com%{REQUEST_URI} [L,R=301]

# prefix everything but /forum/, /wiki/, /blog/, /style/ with /forum/ and rediret to it
RewriteRule !^(forum|wiki|blog|style)/ /forum%{REQUEST_URI} [L,R=301]

The 2nd rule could furthermore be changed by that one to determine the information on the very first path segment for each request.

# check if first segment of requested URI path is either missing
RewriteCond $0 ^$ [OR]
# or cannot be mapped to an existing directory
RewriteCond %{DOCUMENT_ROOT}$0/ !-d
RewriteRule ^[^/]* /forum%{REQUEST_URI} [L,R=301]

I'd say this will work.

RewriteEngine on
RewriteRule ^forum/(.*)$ forum/$1 [L]
RewriteRule ^wiki/(.*)$ wiki/$1 [L]
RewriteRule ^blog/(.*)$ blog/$1 [L]
RewriteRule ^style/(.*)$ style/$1 [L]

RewriteRule ^(.*)$ forum/$1 [L]

RewriteCond  %{HTTP_HOST}  ^www.example\.com$
RewriteRule ^(.*)$ http://example.com/$1