The Digital Ninja
The Digital Ninja

Reputation: 1120

mod rewrite to redirect all except the root

so I have SomeFunnyWebsite.com and ActualSite.com if someone lands on SomeFunnyWebsite.com I want them to see the funny picture but if they goto SomeFunnyWebsite.com/AnyThing I need it to redirect with a 301 to ActualSite.com

        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ http://actualsite.com/$1 [R=301,L,QSA]

But this doesn't redirect to anything. But I have verified that other redirect rules can work.

Upvotes: 0

Views: 167

Answers (1)

jmkeyes
jmkeyes

Reputation: 3781

Try using a rewrite condition that inverts a match on / for the specific domain.

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{HTTP_HOST} ^(www\.)?somefunnywebsite\.com$ [NC]
RewriteRule ^.*$ http://actualsite.com%{REQUEST_URI} [R=301,L,QSA]

I haven't tested it but that should get you started. (I'd suggest using a 302 to start as browsers tend to cache 301 redirects.)

Upvotes: 1

Related Questions