Forum Moderators: phranque

Message Too Old, No Replies

Weird problem with httpd.conf non-www to www rewrites

What is the deal here?

         

eggerda

7:17 am on Mar 21, 2007 (gmt 0)

10+ Year Member



Hello,

I have the following block of code in my httpd.conf file:

<Directory />
Options FollowSymLinks
AllowOverride All
# Begin Rewrite Code
Options +FollowSymLinks
RewriteEngine on
# if hostname is not blank
RewriteCond %{HTTP_HOST} .
# and if hostname does not start with "www."
RewriteCond %{HTTP_HOST}!^www\.
# prepend "www." to hostname and redirect
RewriteRule ^/(.*)$ [%{HTTP_HOST}...] [R=301,L]
</Directory>

I have checked over this, and had some "experts" look over it, and it should be 301 redirecting [site.com...] to [site.com...]

What I stop apache and restart, then test it, it does nothing. What could it be in apache config that isn't allowing these rules to run? I've checked everything!

Thanks,

Dan

jdMorgan

1:19 pm on Mar 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't see anything wrong with that, other than the missing space between "}" and "!" -- possibly an articfact of posting here. The only thing that comes to mind is, did you flush your browser cache before testing?

Other than that, the only other thing to ask is whether mod_rewrite is installed and enabled on this server -- Maybe try a simpler rule like
RewriteRule ^/foo\.html$ http://www.example.com/bar.html [R=301,L]
to be sure.

Jim

eggerda

2:37 pm on Mar 21, 2007 (gmt 0)

10+ Year Member



Hi Jim,

Thanks for the response! It could possibly be the lack of the "space". I'll check it out. Additionally, as far as making sure mod_rewrite is enabled...I have some .htaccess files on sites on this dedicated server mod rewriting fine...does that mean Mod_Rewrite is also enabled at the httpd.conf level, or is there a different setting for this entirely?

Basically, what are the requirements for mod rewrite to work at the httpd.conf level? I just want to make sure there is nothing I am missing...

Let me know when you get a moment.

Thanks!

Dan