Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

.htaccess Redirect problem


Go to End


10 Posts   4883 Views

Avatar
snaip

Community Member, 181 Posts

4 November 2009 at 10:25pm

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

Avatar
dalesaurus

Community Member, 283 Posts

5 November 2009 at 6:48pm

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

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

Avatar
snaip

Community Member, 181 Posts

5 November 2009 at 9:07pm

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

Avatar
dalesaurus

Community Member, 283 Posts

6 November 2009 at 5:03am

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.

Avatar
snaip

Community Member, 181 Posts

6 November 2009 at 8:13am

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 :(

Avatar
dalesaurus

Community Member, 283 Posts

6 November 2009 at 8:32am

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

Avatar
snaip

Community Member, 181 Posts

6 November 2009 at 9:37pm

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 :/

Avatar
dalesaurus

Community Member, 283 Posts

7 November 2009 at 6:59am

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.

Go to Top