Spunkymungbeans
asked on
mod_rewrite for subdomains
I would like to achieve the following with mod_rewrite:
http://www.shire-biz.com - No change
or
http://shire-biz.com - No change
http://foo.shire-biz.com
to
index.php?option=com_webpa ge&usernam e=foo
and
http://foo.shire-biz.com/page1.htm
to
index.php?option=com_webpa ge&usernam e=foo&page =1
This has been suggested but isn't working:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?shire-biz\.com [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.])\.shire-biz \.com [NC]
RewriteRule ^(page([0-9]+)\.htm)?$ /index.php?option=com_webp age&userna me=%2&page =$2 [L]
Max points for urgency. Any help is appreciated.
http://www.shire-biz.com - No change
or
http://shire-biz.com - No change
http://foo.shire-biz.com
to
index.php?option=com_webpa
and
http://foo.shire-biz.com/page1.htm
to
index.php?option=com_webpa
This has been suggested but isn't working:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?shire-biz\.com [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.])\.shire-biz
RewriteRule ^(page([0-9]+)\.htm)?$ /index.php?option=com_webp
Max points for urgency. Any help is appreciated.
ASKER
'foo' is a variable which could be anything. The subdomain represented by 'foo' will never be set up as a virtual host, which is why I need the mod_rewrite.
there's a + missing
([^.]+)
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?shire-biz\.com [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.shire-bi z\.com [NC]
RewriteRule ^(page([0-9]+)\.htm)?$ /index.php?option=com_webp age&userna me=%2&page =$2 [L]
([^.]+)
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?shire-biz\.com [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.shire-bi
RewriteRule ^(page([0-9]+)\.htm)?$ /index.php?option=com_webp
btw. the rewrite rule will only work in per-dir context; if you use it in per-server context (virtualhost, main server config section), you'll need to add a leading slash to the pattern:
RewriteRule ^/(page([0-9]+)\.htm)?$ /index.php?option=com_webp age&userna me=%2&page =$2 [L]
RewriteRule ^/(page([0-9]+)\.htm)?$ /index.php?option=com_webp
ASKER
Sorry its still not working. Here is the entry from my httpd.conf file:
<VirtualHost *>
ServerName shire-biz.com
ServerAlias www.shire-biz.com
DocumentRoot /var/www/html/shirebiz
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?shire-biz\.com [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.shire-bi z\.com [NC]
RewriteRule ^/(page([0-9]+)\.htm)?$ /index.php?option=com_webp age&userna me=%2&page =$2 [L]
</VirtualHost>
You can test it by going to http://www.shire-biz.com. If you type http://smbeans.shire-biz.com you will be taken to another site - the main site on the server. If it works you will remain at shire-biz but be shown a testpage.
<VirtualHost *>
ServerName shire-biz.com
ServerAlias www.shire-biz.com
DocumentRoot /var/www/html/shirebiz
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?shire-biz\.com [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.shire-bi
RewriteRule ^/(page([0-9]+)\.htm)?$ /index.php?option=com_webp
</VirtualHost>
You can test it by going to http://www.shire-biz.com. If you type http://smbeans.shire-biz.com you will be taken to another site - the main site on the server. If it works you will remain at shire-biz but be shown a testpage.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes! That did it.
Here is the full solution:
<VirtualHost *>
ServerName shire-biz.com
ServerAlias www.shire-biz.com *.shire-biz.com
DocumentRoot /var/www/html/shirebiz
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?shire-biz\.com [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.shire-bi z\.com [NC]
RewriteRule ^/(page([0-9]+)\.htm)?$ /index.php?option=com_webp age&userna me=%2&page =$2 [L]
</VirtualHost>
Here is the full solution:
<VirtualHost *>
ServerName shire-biz.com
ServerAlias www.shire-biz.com *.shire-biz.com
DocumentRoot /var/www/html/shirebiz
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?shire-biz\.com [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.shire-bi
RewriteRule ^/(page([0-9]+)\.htm)?$ /index.php?option=com_webp
</VirtualHost>
RewriteCond %{HTTP_HOST} foo.shire-biz.com [NC]
RewriteCond %{REQUEST_URI} ^page.+
RewriteRule ^page(\d+)\.htm index.php?option=com_webpa
RewriteCond %{HTTP_HOST} foo.shire-biz.com [NC]
RewriteRule .+ index.php?option=com_webpa