Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

mod_rewrite for subdomains

Posted on 2005-05-01
7
Medium Priority
?
240 Views
Last Modified: 2010-03-04
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_webpage&username=foo

and

http://foo.shire-biz.com/page1.htm
to
index.php?option=com_webpage&username=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_webpage&username=%2&page=$2 [L]

Max points for urgency.  Any help is appreciated.
0
Comment
Question by:Spunkymungbeans
  • 3
  • 3
7 Comments
 
LVL 19

Expert Comment

by:ramazanyich
ID: 13907411
Try following config:

RewriteCond %{HTTP_HOST} foo.shire-biz.com [NC]
RewriteCond %{REQUEST_URI} ^page.+
RewriteRule ^page(\d+)\.htm index.php?option=com_webpage&username=foo&page=$1 [L]
RewriteCond %{HTTP_HOST} foo.shire-biz.com [NC]
RewriteRule .+ index.php?option=com_webpage&username=foo [L]

0
 

Author Comment

by:Spunkymungbeans
ID: 13908434
'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.
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 13911048
there's a + missing

([^.]+)


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_webpage&username=%2&page=$2 [L]
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
LVL 27

Expert Comment

by:caterham_www
ID: 13911064
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_webpage&username=%2&page=$2 [L]
0
 

Author Comment

by:Spunkymungbeans
ID: 13913353
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-biz\.com [NC]
  RewriteRule ^/(page([0-9]+)\.htm)?$ /index.php?option=com_webpage&username=%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.
0
 
LVL 27

Accepted Solution

by:
caterham_www earned 2000 total points
ID: 13915570
are you sure, that the RWrules are seen by the request there? If you use namebased vhosting and no corresponding ServerName/-Alias was found, the request would go into the first <virtualhost>-Container.

May be you'll need

ServerAlias www.shire-biz.com *.shire-biz.com
0
 

Author Comment

by:Spunkymungbeans
ID: 13915684
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-biz\.com [NC]
  RewriteRule ^/(page([0-9]+)\.htm)?$ /index.php?option=com_webpage&username=%2&page=$2 [L]
</VirtualHost>
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview
Suggested Courses
Course of the Month20 days, 19 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question