Forum Moderators: phranque

Message Too Old, No Replies

Domain redirect with htaccess

having errors

         

Maxformed

6:19 pm on Aug 20, 2003 (gmt 0)

10+ Year Member



Not sure if doing this correctly. Host said to put
[code]
LoadModule rewrite_module modules/mod_rewrite.so
[\code]
in the httpd.conf file - not quite sure where. The host documentation on modules said to put at top of file - does that mean the very first line?

And then to use the following .htaccess
[code]
Options Indexes FollowSymLinks Includes ExecCGI
AddType text/x-server-parsed-html .html
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
# Rewrite Rule for domain-name.net
RewriteCond %{HTTP_HOST} <www.domain.com>
RewriteRule ^(.*)$ [newdomain.com...] [R=301, L]
[\code]

so I did this and got an error - checked the error log and saw
[code]
[Wed Aug 20 11:04:50 2003] [notice] Accept mutex: flock (Default: flock)
Ouch! malloc failed in malloc_block()
Ouch! malloc failed in malloc_block()
... repeats a bunch of times ...

[Wed Aug 20 11:10:44 2003] [alert] [client xxx.xx.xxx.xxx] /usr/local/etc/httpd/htdocs/.htaccess: RewriteRule: bad flag delimiters
[\code]

I'm assuming the bad flag delimiters are in the rewrite condition - but have NO experience with this.

Also, since I usually DON'T use the www.domain.com - do I need two conditions one with www.domain.com and one with just domain.com?

all help appreciated.

thanks
Max

closed

6:41 pm on Aug 20, 2003 (gmt 0)

10+ Year Member



The first thing I would do would be to change this line:


RewriteRule ^(.*)$ http://newdomain.com [R=301, L]

to:


RewriteRule .* http://newdomain.com [R=301,L]

I removed the caret and dollar sign since they were redundant, and removed the space after the comma because the comma is the delimiter in the list.

jdMorgan

7:11 pm on Aug 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maxformed,

You'll have to put your own domain name in the first line, and leave all the "weird" characters in place:


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

This will work for both www and non-www requests, and redirect to the same requested page on the new domain.

Ref: Introduction to mod_rewrite [webmasterworld.com]

You can also get rid of the "Options +FollowSymLinks" line, because SymLinks are already enabled three lines above that in the preceding "Options" line.

The malloc problem is likely related to http.conf, and not to .htaccess. I'm no httpd.conf expert, though; hopefully someone else can help with that.

Jim

Maxformed

7:25 pm on Aug 20, 2003 (gmt 0)

10+ Year Member



Jim - thanks so much - that did it. I also got rid of the malloc problem - apparently I had theLoadModule directive in the wrong spot of the httpd.conf file.

Thanks again,
Max

Maxformed

7:55 pm on Aug 20, 2003 (gmt 0)

10+ Year Member



Oops, I spoke too soon. I forgot about our imanager associated with the original domain - we aren't ready to change the server name just yet.

Can I use the exmple show for several paths

such as
[code]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com\aboutUs\.html [NC]
RewriteRule ^(.*)$ [newdomain.com...] [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com\companies\.html [NC]
RewriteRule ^(.*)$ [newdomain.com...] [R=301,L]
[\code]
and so on so that only the .html files are redirected?

or a rule that everything except domain.com/imanager/ gets redirected to newdomain.com

Sorry to be so block-headed.

thanks
Max

closed

8:37 pm on Aug 20, 2003 (gmt 0)

10+ Year Member



Does this work?


RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain\.com [NC]
RewriteCond %{REQUEST_URI} .*\.html$
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]

If the host is yourdomain.com and the file name ends with .html, apply the rule.

Or you could try this:


RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain\.com [NC]
RewriteCond %{REQUEST_URI}!^/imanager/
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]

If the host is yourdomain.com and the requested URI begins with /imanager/, apply the rule.

Of course, I'm still a newbie, so it may not be entirely right.

closed

8:42 pm on Aug 20, 2003 (gmt 0)

10+ Year Member



For the second block of code, there's supposed to be a space between {REQUEST_URI} and the exclamation point (!).

Also, my explanation for that block of code should have been: If the host is yourdomain.com and the requested URI does not begin with /imanager/, apply the rule.

Maxformed

8:50 pm on Aug 20, 2003 (gmt 0)

10+ Year Member



Thanks, closed. The first option worked. A lifesaver - especially for someone as confused by where to use which condition stuff.

Excellent help from you and jdMorgan.

thanks so much.
Max

jdMorgan

9:17 pm on Aug 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maxformed,

You can shorten that up a bit, since, by definition, RewriteRule examines a derivative of {REQUEST_URI}:


RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain\.com [NC]
RewriteRule ^(.*)\.html$ http://newdomain.com/$1.html [R=301,L]

closed's second block of code, amended as noted (with a space preceding "!") should work as-is.

Jim

Maxformed

12:35 pm on Aug 21, 2003 (gmt 0)

10+ Year Member



Thanks, Jim. I'll look at that this morning.

Max