Forum Moderators: phranque
I looked around and found this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
but that's for the .htaccess file. I tried it and it worked just fine, for the main domain at least. The other domain is in a subfolder and it gets all messed up when I try to use the RewriteEngine on it.
I realize this question is slipping away from the php side of questions... if there isn't a php solution i'll post this part of it in a different forum, but I'll continue here for now.
The server is setup like this:
public_html/domain1.php
public_html/domain2/domain2.php
When I use the RWEngine for domain2 and I type, say,
"www.domain2.com/index.php"
it redirects me to
"domain2.com/domain2/index.php"
which would be the right path if it were on domain1, but it's not... I found this:
[httpd.apache.org...]
But it didn't help much.
For domain1 it works fine
www.domain1.com/sadfa/asdfase/sdf.php goes to
domain1.com/sadfa/asdfase/sdf.php
I need it to do that for domain2 but I couldn't find what the $1 was. I tried $2 and it took me from
www.domain2.com/whatever/index.php to
domain2.com/
This is kind of a hack around the original problem anyway. Though getting either/both to work would be helpfull.
Thanks,
Adam
PS:
I know that at the top of every file I could put something
using HTTP_HOST and PHP_SELF, and strip the www if
it exists and use header("Location: ...")
but it would be nicer if I could tell php to store the PHPSESSID somewhere where there "www" wouldn't make a difference so it only paid attention to the domain itself.
If it's not much trouble for anyone who might know, it would still be nice to know how to have gotten it working from the public_html directory as well.
-Adam
The reason that $2 didn't work is that there was no second parenthesized sub-pattern defined in your RewriteRule's pattern, so $2 was blank.
You could use a 'common' .htaccess only if both domains resolve to the same directory path -- This is the DocumentRoot setting in the httpd.conf server configuration file. As far as the 'rules' of the Web go, www- and non-www domains are not at all 'the same thing'; www.example.com is a subdomain of example.com, and need not host the same content, any more so than 'search.example.com' would be expected to host the same content.
Jim