Mod rewrites and add on domains help

luckyga1

New member
Apr 1, 2010
26
0
0
www.luckygame.co.uk
Ok, so need some help here please :

Ive a main domain and an add on domain, the thing is,the add on domain is a database driven site and im trying to create pretty urls for it.

Both domains have seperate htaccess files, and ive added redirects etc to the add on domain which work fine, but whatever mod rewite i add to the add on domain it just doesn't read it and the links dont change.

Ive checked the actual mod outside of the domain and it works fine, just not when its in the add on domains htaccess file. So im guessing the path may be wrong?

Is there a way a create a mod rewrite that is add on domain specific?

Any help would be appreciated...thanks
 


You don't want to do this with .htaccess, the most elegant way of doing it is with httpd.conf. I wrote this code for a project of mine that takes any incoming add-on domain and automatically creates a subfolder for it, populates it with wordpress -- without requiring an apache reboot.

In your httpd.conf file on apache:

Code:
NameVirtualHost (your ip address)
<VirtualHost (your ip address)>
DocumentRoot "c:/wamp/www/yourdirectory"
RewriteEngine  On
ErrorDocument 404 /error.php
RewriteRule ^/error\.php$ - [L]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^(.*)$ /%{HTTP_HOST}/$1 [L]
</VirtualHost>
This code will go at the top of your namevirtualhosts, that will make it the catchall for that particular IP address.

The way this works, it tries to load /yourdirectory/domain. So lets say you point example.com to your server's IP address, this code for your catchall domain will try to load /yourdirectory/example.com/

Of course, it will fail -- because that directory doesn't actually exist. When it fails, it will try to load the error.php referenced above. The error.php sits in your /yourdirectory/ folder ... and when an error is thrown because the /example.com/ directory doesn't exist, it will load the error.php file.

This error.php file will contain everything necessary to populate that directory. On my project, I unzip the latest version of wordpress and copy it to the /yourdirectory/example.com/ directory. Once that directory actually exists ... it will load that directory for the incoming add-on domain without needing to reboot apache.

This file automatically redirects www to non-www (so it knows to grab it from the directory /example.com/ instead of /www.example.com/ Unfortunately, people who just love www instead of no-www will have to come up with another solution for this dilemma, I guess rewrite non-www to www and force it always as www, but I'm assuming you can figure that out if you want to.

BTW I pulled my hair out for days getting this to work. :p If you need more help, PM me.