www.webdeveloper.com
Results 1 to 7 of 7

Thread: .htaccess woes

Hybrid View

  1. #1
    Join Date
    Apr 2010
    Posts
    3

    .htaccess woes

    I am trying to set up canonical redirects in my .htaccess file in order to manage my domains. The situation is complicated by the fact that there is already a set of rewrite rules in place for the CMS, (Joomla). My approach was to not mark the canonical redirects as final, and to place them before the SEF rewite rule block for Joomla.

    I added this block of instructions:

    ######### create canonical domains ##################

    RewriteCond %{HTTP_HOST} ^3dify.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.3dify.com$ [OR]
    RewriteCond %{HTTP_HOST} ^threedify.com$
    RewriteRule ^/?(.*) "http://www.threedify.com/$1" [R=301,NC]

    The result sort of works, in that a request for pages at 3dify.com, threedify.com, or www.3dify.com will always return http://www.threedify.com/index.php. The problem is that the rest of the URL is ignored instead of being appended to the new domain, so any request for a page at a non-canonical domain ALWAYS redirects to the site index.

    This isn't what I want. I would like to return the requested page from the canonical URL, not redirect to the site root. Why is the $1 getting chomped? Does anyone have any ideas for me?

    Thanks very much,

    Chris Ivey, Marketing Director, ThreeDify

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Is this what you want to do?
    http://snipplr.com/view/4604/force-www-in-url/

  3. #3
    Join Date
    Apr 2010
    Posts
    3

    Problem has been resolved

    Actually, no, that isn't what I wanted to do. If you look at the rules I wrote, You'll see that I wanted to rewrite 3 domains to match the canonical domain. It turns out that if I set the rule to final (add an "L" flag) it completes processing on the canonical redirect before applying the SEF rewrite block for the CMS. This will work provided my rewrite block appears before the CMS block.

  4. #4
    Join Date
    Jan 2007
    Location
    Wisconsin
    Posts
    2,120
    I use this on Svidgen ...

    Code:
    RewriteCond %{HTTP_HOST} !^www\.svidgen\.com$ [NC]
    RewriteRule ^(.*)$ http://www.svidgen.com$1 [R=301,L,NE]
    So, if you have multiple virtual hosts listed, you would put something like this in the top-listed host as a catch-all. All hosts that don't explicitly match a virtual host get routed to the first-listed virtual host. Such requests are then redirected to the preferred hostname. (if they are not already requests for the preferred hostname)

  5. #5
    Join Date
    Apr 2010
    Posts
    3

    pretty cool, but is it dangerous?

    That's pretty slick, but is there any danger of it redirecting traffic you don't want to go there? Obviously, you couldn't use a ! operator if you had to contend with http and https requests...

  6. #6
    Join Date
    Jan 2007
    Location
    Wisconsin
    Posts
    2,120
    Quote Originally Posted by ThreeDify View Post
    That's pretty slick, but is there any danger of it redirecting traffic you don't want to go there? Obviously, you couldn't use a ! operator if you had to contend with http and https requests...
    No danger as far as I can see. Worst case, someone accidentally points their domain at my IP and http://somepornsite/somethingsick.html gets redirected to http://www.svidgen.com/somethingsick.html, which will in turn show my 404 page.

    In terms of confusing http/https traffic, you're out of luck using name-based virtual hosts anyway. The Host header isn't visible to apache until it locates the most appropriate [virtual] host anyway.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles