Forum Moderators: phranque
i have for example:
www.domain1.com
www.domain2.com
www.domain3.com
i thenn have 3 folders inside the root directory for the web server of
/domain1/
/domain2/
/domain3/
currently i have a php script in the root of the web server which redirects to the correct directory, so the users get redirected to
[domain1.com...]
[domain2.com...]
[domain3.com...]
but this doesn't look very good, so i would like to use Rewrites to achieve this, this is what i have come up with so far:
RewriteEngine on
# append hostname to URL
RewriteRule (.*) %{SERVER_NAME}\%2f$1
# strip leading www. if it exists
RewriteRule ^www\.(.*) $1
# remove .com/.net/.org extensions
RewriteRule ^([^/]*).net(.*) $1$2
RewriteRule ^([^/]*).com(.*) $1$2
RewriteRule ^([^/]*).org(.*) $1$2
anyone see what the error is in my rewrite rules?
i think the problem is with the fact that i used %2f in place of the / - however if i try to use a / then i get a 500 error so thats why i used %2f instead
i managed to get the server to do something by changing the com¦net¦org in the example you gave to *
RewriteEngine on
# Get domain from request HTTP_HOST header
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)(.+)
# Rewrite the request to domain-specific subdirectory
RewriteRule (.*) /%2/$1 [L]
however, that something was a 500 error until i changed the last line to
RewriteRule (.*) /%2\%2f$1 [L]
when it gave a 404 instead
First, the code may loop unless this is explicitly prevented:
RewriteEngine on
# Prevent "infinite" rewrite loop
RewriteCond $1 !^(domain1¦domain2¦domain3)/
# Get domain from request HTTP_HOST header
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.(com¦net¦org)
# Rewrite the request to domain-specific subdirectory
RewriteRule (.*) /%2/$1 [L]
If you still get a 500-Server Error with the modified code above, then please report the contents of your server error log file.
Jim
the .htaccess file works great, thanks for posting this script. but i'm having trouble with the cgi-bin.
/cgi-bin/
/htdocs/domain1/
/htdocs/domain2/
domain2 isn't resolved yet (just got it) but i can't access the cgi-bin from domain1/cgi-bin
does anyone know how to get it to redirect to the /cgi-bin/ or how to setup the .htaccess file to allow multiple cgi-bin diretories?
The most likely cause is that your cgi-bin directory is aliased in httpd.conf. So, requests for /cgi-bin are "rewritten" before your .htaccess code can have any effect on them.
The simplest solution is to use a different name, like "cgi_bin" or "cgi-b". Be sure to lock down the file permissions of your new cgi-bin directories, and consider adding password protection to the execute-only scripts; The reason many hosts alias the cgi-bin directory is so that the actual files can be placed in a directory which is not directly Web-accessible.
Jim