Forum Moderators: phranque
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
[edited by: phranque at 12:57 am (utc) on Jul 14, 2013]
[edit reason] unlinked url [/edit]
that trailing backslash was supposed to be an escape of the trailing blank, which would essentially end-anchor the requested url path in THE_REQUEST.
even if the "strange" file endings are redirected they should still generate a 404 if the file does not exist and your server is configured properly
/test/index.html56456 meets your condition and goes to /test/ where there is a valid index.php|html? so it loads with no error.
you want to avoid redirecting a request that's going to end up as something other than 200
This has nothing to do with subdomains or blog software of any kind.
2 - The actual subdomain location is /blog/, but that should never be accessible to people or engines. So, /blog/* should always be blog.example.com/*
# Externally redirect client requests for www.<subdomain>.example.com/<URLpath> to <subdomain>.example.com/<URLpath>
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://%1%{REQUEST_URI} [R=301,L]
to
# Externally redirect client requests for www.<subdomain>.example.com/<URLpath> to <subdomain>.example.com/<URLpath>
RewriteCond %{HTTP_HOST} ^www\.(.+)\.example\.com$
RewriteRule ^subs/([^/]+)/(.*)$ http://$1.example.com/$2 [R=301,L]
it really had nothing to do with the subdomain setup or original reason for the post. It just removes the index file from the url and preserves the parameters if any.
Say someone posts a ton of malformed index links to your site.
if I get a ton of links like you're talking about if it turns into an issue I can either disavow or take the redirect down.