Jump to:

23379 Posts in 18298 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » .htaccess Redirect problem

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 2952 Views
  • snaip
    Avatar
    Community Member
    180 Posts

    .htaccess Redirect problem Link to this post

    hi

    i have multi language site (PL,DE) and two domains

    domain A should be the main domain of PL version
    domain B should redirect to german main page

    so in htaccess i put

    RewriteCond %{HTTP_HOST} ^domain.de
    RewriteRule (.*)$ http://www.domain.de/de [R=301,L]

    and it works but only when domain doesn't start with "www"

    i put another rule

    RewriteCond %{HTTP_HOST} ^domain.de [OR]
    RewriteCond %{HTTP_HOST} www.domain.de
    RewriteRule (.*)$ http://www.domain.de/de [R=301,L]

    but now nothing works
    there is some problem with this rule: RewriteCond %{HTTP_HOST} www.domain.de
    always get an error
    "Moved Permanently The document has moved here."

    and another question
    why when i have: RewriteCond %{HTTP_HOST} ^domain.de
    and enter the site i get a ?url=/de at the end of the URL ?
    http://www.domain.de/de?url=/de

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: .htaccess Redirect problem Link to this post

    You have to evaluate rewrites in priority, and this case make the www optional.

    http://wiki.apache.org/httpd/RewriteMassVhosting

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: .htaccess Redirect problem Link to this post

    hmm

    RewriteCond %{HTTP_HOST} !^www\.domain.de
    RewriteRule (.*)$ http://www.domain.de/de [R=301,L]

    domain.de => redirect to DE main page GOOD
    www.domain.de => redirect to PL main page BAD

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: .htaccess Redirect problem Link to this post

    Sorry I was posting last night when I should have been sleeping, what I wrote wasn't useful at all.

    So to do the optional www, I don't think using ! (nots) for negative matching is the best approach. Maybe something like this

    RewriteCond %{HTTP_HOST} ^.*domain\.de$ [NC]
    RewriteRule ^(.*)$ http://www.domain.de/de/$1 [R=301,L]

    I didn't test that, so let me know if it works.

    The ?url=/de part is something I've run into quite often with SS. The short answer is append a / to the end and it will go away, like http://www.site.com/de/

    It has to do with some wonky matching and necessary voodoo in the HTTPResponse. Well that is my opinion as I understand the code that is.

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: .htaccess Redirect problem Link to this post

    thanks for helping but still nothing
    now both of domains get 301 ERROR

    hmm
    is it possible to redirect www.domain.de to domain.de and than to http://www.domin.de/de ? maybe it is stupid way but i dont have any idea

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: .htaccess Redirect problem Link to this post

    That would be the R=301 at work, remove it so that it is just [L] if it is the last rule. You might have to get comfy with other tutorials and man pages for mod_rewrite: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: .htaccess Redirect problem Link to this post

    i tried to do the same by PHP

       function redirect() {
          $adress = 'http://'. $_SERVER['HTTP_HOST'];

          if($adress == 'http://www.domain.de') {
             ob_start();
             header('Location: http://www.domain.de/de');
             ob_end_flush();
          }
       }

    but i get error 301 too !!

    i do not understad what the **** is going on :/

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: .htaccess Redirect problem Link to this post

    Sorry but this is beyond my RewriteEngine On skills. You might try on IRC or in another apache forum where there are experts better suited to help you out.

    2952 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.