301 redirects, trailing slashes and folders that begin with an underscore

Discussion in 'Server Operation' started by sfunk1x, Apr 11, 2010.

  1. sfunk1x

    sfunk1x New Member

    Hey all -

    I'm running into an issue with an .htaccess file with some 301 redirects.

    I'm running a server that has a site which has an .htaccess file redirecting several domain names to another single canonical name. Those redirects work great, until you try going to a particular subfolder of a site which starts with an underscore, for example:

    oldsitedomainname.com/_admin

    would be redirected to:

    http://www.newsitedomainname.com/_admin

    however, it's actually being re-written like this:

    http://www.newsitedomainname.com_admin

    which doesn't work for obvious reasons.

    I added the following code snippet from a 301 howto in order to add a trialing slash to URLs, which seems to work great, but that hasn't solved the problem:

    rewriteCond $1 !/$
    rewriteCond %{REQUEST_FILENAME}/ -d
    rewriteRule (.+) http://www.newsitedomainname.com/$1/ [R=301,L]

    Anyone have any suggestions? Thanks in advance!
     
  2. sfunk1x

    sfunk1x New Member

    Wow, so no one uses 301 redirects? Is there another method I could use to perform this same function?

    Also, I'm running into a problem of the redirects only redirecting non-www addresses. Anytime someone prepends a www to the address, it won't get re-written.
     
  3. drieschel

    drieschel New Member

    Hi sfunk1x,

    try this:

    RewriteCond %{HTTP_HOST} !^www\.newsitedomainname\.com [NC]
    RewriteCond %{HTTP_HOST} !^$

    RewriteRule (.*) http://www.newsitedomainname.com/$1 [R=301,L]

    Maybe it will work.

    Greetz
    drieschel
     
  4. sfunk1x

    sfunk1x New Member

    Wow, that took care of it. Thank you very much!
     

Share This Page