Forum Moderators: phranque

Message Too Old, No Replies

.htaccess redirect

mysite.ca to mysite.com, same server

         

cybertime

7:25 pm on May 27, 2006 (gmt 0)

10+ Year Member



example.ca and example.com are being hosted on the same server and I wanted to set-up a redirect:

Options +FollowSymLinks
RewriteEngine on
# if not the correct domain
RewriteCond %{HTTP_HOST} ^(www\.)?example\.ca [NC]
# redirect to correct domain
RewriteRule (.*) http://example.com/$1 [R=301,L]

after adding this to the .htaccess, example.ca does not redirect to example.com. Not sure what I did wrong. Here is a copy of my .htaccess file.

Thanks.

# -FrontPage-
IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

SetEnvIf Request_URI "^(/403.*\.htm?:/robots\.txt)$" allowit
# Block bad-bots using lines written by bad_bot.pl script above

# Ban .htaccess & .htpasswd requests
SetEnvIfNoCase Request_URI \.ht(access¦passwd)$ ban

<Files *>
Order deny,allow
Deny from env=ban
Deny from env=getout
Allow from env=allowit
</Files>

Options +FollowSymLinks
RewriteEngine on
# if not the correct domain
RewriteCond %{HTTP_HOST} ^(www\.)?example\.ca [NC]
# redirect to correct domain
RewriteRule (.*) http://example.com/$1 [R=301,L]

RewriteEngine on
RewriteRule ^/?http:// - [F]

Options +FollowSymLinks
RewriteEngine on
RewriteRule (mail.?form¦form¦form.?mail¦mail¦mailto¦sendmail)\.(cgi¦exe¦pl¦asp¦php¦pm)$ /cgi-bin/trap.pl [NC,L]

<snip>

[edited by: jdMorgan at 9:39 pm (utc) on May 27, 2006]
[edit reason] Code dump, example.com [/edit]

jdMorgan

9:42 pm on May 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You had two (and more) instances of Options and RewriteEngine on directives in that file. Only the first is needed.

The following will prevent your annoyances code from working properly; The last RewriteCond before a RewriteRule must never have an [OR] flag.


# Covenant Eyes
RewriteCond %{REMOTE_ADDR} ^69\.41\.14\.([1-9]?[0-9]¦1[01][0-9]¦12[0-7])$ [OR]
RewriteRule - [F]

Howeer, neither of those should affect the domain redirection. The most likely cause is that those alternate domains to not resolve to the same DocumentRoot, and therefore, your .htaccess file is not executed when those domains are requested.

Jim