Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-04-25 00:33:46

wolfcry911
Member
From: MA, USA
Registered: 2006-06-30
Posts: 51

help with htaccess rewrite/redirection

Hello,
I have 3 domains for the same site and to avoid duplicate content I want to redirect all traffic to one domain with the www prefix. I’ve searched the forum and found some help, but in application doesn’t seem to work. I’m hoping there’s an htaccess guru here that can help.

I would like domainA, domainB, and domainC (all with or without www.) to be rewritten to www.domainA.com
I would also like for directories/files to be rewritten, so domainB.com/news/article1 would redirect to www.domainA.com/news/article1

This may be where my problem lies as I have txp set to section/title URLs (I’m not really sure, but I’ve been pulling my hair trying to get this to work).

#DirectoryIndex index.php index.html

#Options +FollowSymLinks
#Options -Indexes
#ErrorDocument 403 default

<IfModule mod_rewrite.c>
	RewriteEngine On
	#RewriteBase /relative/web/path/

RewriteCond %{HTTP_HOST} !^www\.domainA\.com$ [NC]
RewriteRule ^(.*)$ http://www.domainA.com/$1 [QSA,R=301]

	RewriteCond %{REQUEST_FILENAME} -f [OR]
	RewriteCond %{REQUEST_FILENAME} -d
	RewriteRule ^(.+) - [PT,L]

	RewriteCond %{REQUEST_URI} !=/favicon.ico
	RewriteRule ^(.*) index.php

	RewriteCond %{HTTP:Authorization}  !^$
	RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
</IfModule>

#php_value register_globals 0

This is my latest attempt and doesn’t work. It won’t rewrite the domain or the directory and I lose css and javascript files when viewing the page (for all combinations other than www.domainA.com, which works fine).

Offline

#2 2011-04-25 00:45:48

wolfcry911
Member
From: MA, USA
Registered: 2006-06-30
Posts: 51

Re: help with htaccess rewrite/redirection

I just made a change and came much closer, but there’s still a glich. Here’s what I changed to:

#DirectoryIndex index.php index.html

#Options +FollowSymLinks
#Options -Indexes
#ErrorDocument 403 default


<IfModule mod_rewrite.c>
	RewriteEngine On
	#RewriteBase /relative/web/path/

	RewriteCond %{REQUEST_FILENAME} -f [OR]
	RewriteCond %{REQUEST_FILENAME} -d
	RewriteRule ^(.+) - [PT,L]

	RewriteCond %{REQUEST_URI} !=/favicon.ico
	RewriteRule ^(.*) index.php

	RewriteCond %{HTTP:Authorization}  !^$
	RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
</IfModule>

#php_value register_globals 0

RewriteCond %{HTTP_HOST} !^www\.dclatham\.com$ [NC]
RewriteRule ^(.*)$ http://www.dclatham.com/$1 [QSA,R=301]

With this rule outside of TXP’s rules, the rewrite works to a degree. The domain is changed correctly, but it’s appended with index.php. Here’s some examples:

domainB.com/news ==> www.domainA.com/index.php

domainB.com/news/article1 ==> www.domainA.com/index.php/article1 (I found this one interesting)

domainC.com ==> www.domainA.com/index.php (here the index.php was added when the URI didn’t contain a directory/file extension – txp addition?)

Last edited by wolfcry911 (2011-04-25 00:46:21)

Offline

#3 2011-04-25 02:41:47

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,477

Re: help with htaccess rewrite/redirection

I would like domainA, domainB, and domainC (all with or without www.) to be rewritten to www.domainA.com:

<<IfModule mod_rewrite.c>

	RewriteEngine On
	RewriteBase /

	RewriteCond %{http_host} !^www\.domainA\.com$ [NC]
	RewriteRule ^(.*)$ http://www.domainA.com/$1 [R=301,L]

	RewriteCond %{REQUEST_FILENAME} -f [OR]
	RewriteCond %{REQUEST_FILENAME} -d
	RewriteRule ^(.+) - [PT,L]

	RewriteCond %{REQUEST_URI} !=/favicon.ico
	RewriteRule ^(.*) index.php

	RewriteCond %{HTTP:Authorization}  !^$
	RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]

</IfModule>

Offline

#4 2011-04-25 12:00:09

wolfcry911
Member
From: MA, USA
Registered: 2006-06-30
Posts: 51

Re: help with htaccess rewrite/redirection

GugUser, thank you so much.
I could swear I had tried using the Last flag before, but I probably had a different Cond at that time.

At any rate, that works perfectly!
Thanks again,
Chris

Offline

Board footer

Powered by FluxBB