Forum Moderators: phranque
I want to redirect any request for //domain.com/dir/* to just reroute to my main //domain.com with a 301 for the SE's. I want it recursive as there are hits for random subdirectories in there and random files, too many to single out and put into the htaccess.
So far I have this:
# no-www please
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]# 301 Permanent Redirects
Redirect 301 /dir http://example.com/
Now that takes for example a request for //domain.com/dir and redirects it fine... BUT.. if at request for //example.com/dir/subdir or //example.com/dir/file.jpg comes in... it sends it to //example.com/subdir or //example.com/file.jpg and then 404's again... so it's just removing /dir/
...with that said.... help please :)
[edited by: jdMorgan at 10:55 pm (utc) on Oct. 10, 2007]
[edit reason] example.com [/edit]
# Redirect "dir/*" to "/"
RewriteRule ^dir/ http://example.com/ [R=301,L]
#
# no-www please
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
What tripped you up is the prefix-matching of the Redirect directive; Any part of the URL-path not matched by the specified URL-path prefix in a Redirect directive is appended to the substitution URL. Mod_rewrite uses regular expressions, and behaves differently, in that back-references must be explicitly created and invoked.
Jim
[edited by: jdMorgan at 10:54 pm (utc) on Oct. 10, 2007]