Forum Moderators: phranque

Message Too Old, No Replies

How to redirect this?

         

pavieira

8:25 pm on Aug 28, 2009 (gmt 0)

10+ Year Member



Hello,

I have a website running Joomla on the root of my public_html folder.

I need to run another site that will be located on a subfolder of my public_html, like this:

public_html/otherexample

The .htaccess Joomla generated is redirecting the acesses to a 301 error page when i try to access this other site.

On the .htacess file there's the following code:

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

How can i write the following:

If the host is www.otherexample.com, open this site as usual, but if it's anything else, keep the code above?

[edited by: jdMorgan at 11:19 pm (utc) on Aug. 28, 2009]
[edit reason] example.com [/edit]

pavieira

10:00 pm on Aug 28, 2009 (gmt 0)

10+ Year Member



Does this seems right?

RewriteCond %{HTTP_HOST} ^www.otherexample.com$
RewriteRule ^(.*) $1 [L]

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

[edited by: jdMorgan at 11:18 pm (utc) on Aug. 28, 2009]
[edit reason] example.com [/edit]

jdMorgan

11:28 pm on Aug 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd suggest:

# Redirect to canonical domain if the requested hostname contains "otherexample.com" but is non-canonical
RewriteCond %{HTTP_HOST} otherexample\.com [NC]
RewriteCond %{HTTP_HOST} !=www.otherexample.com
RewriteRule ^(.*) http://www.otherexample.com/$1 [R=301,L]
#
# Else redirect to canonical domain if the requested hostname contains "example.com" but is non-canonical
RewriteCond %{HTTP_HOST} example\.com {NC}
RewriteCond %{HTTP_HOST} !=www.example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

This fixes all canonicalization problems for all requested domains. The default domain is "www.example.com".

Note that regex patterns and string-match patterns have different syntax; The literal periods in regex patterns must be escaped as shown, and the literal periods in string-match patterns must NOT be escaped.

Jim