1

I'm in a situation and haven't been able to find a proper solution after much research. I'm working with a client who just built a new website with a different URL structure. After the website was complete, I began to tackle any canonicalization issues for proper SEO and site organization. I was able to solve the www vs non-www version of the site being displayed using .htaccess, which made me feel I would be able to 301 all of the old URLs to their corresponding new URLs. I was wrong. I haven't been able to get a single 301 redirect to perform through .htaccess. Instead, I get a 404 page with little clues that reveal my client may be on an IIS server, which I think is a little strange because the .htaccess is working(somewhat).

I'm hoping that it's just the syntax of my .htaccess file to solve www vs non-www that's stopping all other 301 redirects from being completed. Here is what the current .htaccess file looks like.

 RewriteEngine On
 RewriteBase /
 Options +FollowSymLinks
 RewriteCond %{THE_REQUEST} ^.*/index.php
 RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L]
 RewriteCond %{HTTP_HOST} ^example.com [NC]
 RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Is there anything I've unintentionally added above that would interfere with doing a 301 redirect for other URLs? Such as:

 Redirect 301 /old.htm http://www.example.com/products/side-by-side.htm

Within some of the new product directories exists .htaccess files that are rewriting PHP URLs into cleaner, user friendly URLs. Could this have an effect?

3
  • Before continuing to fiddle with this why are you not addressing the "IIS or not" question first? Apparently there are ways of getting htaccess supported under IIS(I never work on it), if that's even what's going on, but even so there may be quirks. You need to know what you're actually working with.
    – Su'
    Aug 20, 2012 at 17:00
  • Unfortunately, the client outsourced the development of the website. The first thing I did when I noticed hints of an IIS server was contact the client to have their development team remedy the situation(I, too, do not work with IIS). However, they do not understand what is trying to be accomplished as they sent me back the most ridiculous .htaccess file that made matters worse. I'll attempt to gather more information. Thank you.
    – Cody Sharp
    Aug 20, 2012 at 17:49
  • It is an IIS server using .htaccess and PHP.
    – Cody Sharp
    Aug 22, 2012 at 15:08

1 Answer 1

3

I ended up solving the problem. The below syntax does not work:

 Redirect 301 /old.htm http://www.example.com/category/new.htm

However, this syntax works:

 RewriteRule old.htm /products/new.htm [R=301,L]

I'm not really sure why the first example doesn't work, but the second works. Perhaps, it's because the .htaccess is on an IIS server and only understands certain syntax structures for redirects. I feel it's also important to note that the beginning of the old URL for the working redirect does not start with a slash, this may be due to the "RewriteBase /" line in the file.

2
  • Well, on Apache, "the old URL for the working redirect does not start with a slash" because the per-directory prefix is removed from the URL-path before pattern matching - it has nothing to do with the RewriteBase directive. In fact, the RewriteBase directive is only required when you have relative path substitutions in the RewriteRule. In the examples here, the RewriteBase directive is not actually doing anything (on Apache at least).
    – MrWhite
    Mar 21, 2015 at 0:01
  • "the .htaccess is on an IIS server" - .htaccess is not native to IIS and requires 3rd party plugins to work at all. It's possible you have a plugin that is "only" emulating mod_rewrite in .htaccess. Redirect is a mod_alias directive, so that may well be the reason.
    – MrWhite
    Feb 10, 2016 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.