Forum Moderators: phranque
So, I'm using an open source CMS which has search engine friendly url functionality, using an .htaccess file in the root directory.
My problem is that I'm trying to create an add on domain on my host, served from a subdirectory in which I'll the domain's site.
I used my ISP's admin tool to point the new domain at the subdirectory, and that created the following in the httpd.conf file:
<VirtualHost *>
ServerName mynewdomain.com
ServerAlias www.mynewdomain.com
DocumentRoot /www/htdocs/sites/mynewdomain
</VirtualHost>
And, within that directory there's an .htaccess with the following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
The search engine friendly url's work fine when I surf to mydomain.com/sites/mynewdomain/. Everything works like a charm. However, if I go to mynewdomain.com, the site is there, but the SEF urls give 404's everytime, although they work in their default state (i.e. mynewdomain.com/index.php?id=12).
I tried every RewriteBase I could think of, buy I'm thinking this isn't even the problem, and it's probably an issue of the httpd.conf code, and the .htaccess code confusing Apache.
Anyway, I'm beyond my meager knowledge of Apache and mod_rewrite, so any help at all would be much appreciated.
Thanks in advance.
1) error.log: if you're getting a 404, the file that's being requested will be logged there (the full path to it). Is it the path you were expecting?
2) Use the RewriteLog [httpd.apache.org] and RewriteLogLevel [httpd.apache.org] directives (note: do NOT use these on a production host which sees any amount of actual traffic; use it on a test box (or at least a test <VirtualHost>) so that you don't bring your system to a halt with the copious logging that
RewriteLogLevel 9 produces. =)
In the RewriteLog, I see this for one reguest for one of the files that yields a 404:
68.123.141.75 - - [28/Apr/2005:20:05:21 -0600] [newdomain.com/sid#8108dd8][rid#81a4d78/initial] (2) init rewrite engine with requested uri /test-this.html
68.123.141.75 - - [28/Apr/2005:20:05:21 -0600] [newdomain.com/sid#8108dd8][rid#81a4d78/initial] (1) pass through /test-this.html
Does the "pass through" indicate that the rewrite conditions aren't being met, in which case it would do nothing and hence not find the file?
I've also tried to put the rewrite code withing the <VirtualHost> tags in httpd.conf, but that breaks everthing and gives a 400 error for the whole site. The documentation seems to indicate that this is acceptable, but apparently I'm not doing it right, or the rewrite code would need to be changed in order to live in the httpd.conf, as opposed to the .htaccess.
Highly frustrating, this stuff. Wish I knew more about Apache.
Thanks for your help.
Does the "pass through" indicate that the rewrite conditions aren't being met, in which case it would do nothing and hence not find the file?
Not quite, but in order to realize why, you need to re-read the 'Ruleset Processing' section of the mod_rewrite documentation [httpd.apache.org].
I've also tried to put the rewrite code withing the <VirtualHost> tags in httpd.conf, but that breaks everthing and gives a 400 error for the whole site. The documentation seems to indicate that this is acceptable, but apparently I'm not doing it right, or the rewrite code would need to be changed in order to live in the httpd.conf, as opposed to the .htaccess.
GET index.php?q=/something HTTP/1.0
Which is invalid because the path isn't valid.)
Also note that your parens will capture a leading '/' in the incoming URL. If you don't want this; you'll want to tweak your RewriteRule so that it looks like:
RewriteRule ^/(.*)$ /index.php?q=$1 [L,QSA]
Highly frustrating, this stuff. Wish I knew more about Apache.
mod_rewrite has a steep learning curve; if your regex-fu isn't all that strong, the learning curve is even steeper. =)
Anyway, another kind soul finally put me out of my misery on this one, by suggesting that I change the DocumentRoot to a true path, like:
/var/www/html/sites/newdomain
turns out, the old one (created by the isp's admin tool) included sym links, and that was causing the problem. I changed it, and it works like a charm. Now, can I have some of those hours I spent playing with this thing back? :)
Thanks for your input, sitz. And, thanks again to everybody for Webmaster World.