Help needed with virtual sub domains and some other bits.

New to mod_rewrite? This is a good place to start.

Postby richardk » Fri Nov 23, 2007 1:25 pm

The biggest change is the second from last RewriteCond (that you should change even if you don't use the below)
Code: Select all
RewriteEngine On

RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 9

RewriteMap domain2website txt:/etc/apache2/domain-websitemap.map

#don't rewrite these references, leave them as is
RewriteRule ^/static(/.*)?$ - [NC,L]
RewriteRule ^/thepencilroom/(app|response|contact|cart)(/.*)?$ - [NC,L]

#if the url is blank other than the domain, add "home" to it and continue
RewriteRule ^/$ /home [R,L]

#to allow the system to work without apache (ie, just using tomcat) most urls written will put in "thepencilroom"
#to get to the servlet, but because when using apache "thepencilroom" is automatically added
#if the incoming url contains the text, then remove it
RewriteRule ^/thepencilroom/(.*)$ /$1 [R,L]

#quick access to the admin console via admin.example.com
RewriteCond %{HTTP_HOST} ^admin\.example\.com$ [NC]
RewriteRule .* /thepencilroom/app [QSA,PT,L]

#do the virutal mass hosting
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com$ [NC]
RewriteRule .* /thepencilroom%{REQUEST_URI}/website/%2 [QSA,PT,L]

#do the mapping from a real registered domain to the appropriate example website
RewriteCond %{HTTP_HOST} !^(.*\.)?example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(.+)$ [NC]
RewriteCond ${domain2website:%1|:} ^([^:]+)$
RewriteRule .* /thepencilroom%{REQUEST_URI}/website/%1 [QSA,PT,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby andrewpmoore » Sun Jul 12, 2009 10:03 pm

Coming back to this post after a long time, but I've now got an SSL certificate and my apache to tomcat SSL is working fine.

When somebody enters admin.example.com it redirects them to admin.example.com/ff/app

Code: Select all
#quick access to the admin console via admin.example.com
RewriteCond %{HTTP_HOST} ^admin\.exmaple\.com$ [NC]
RewriteRule .* /ff/app [QSA,PT,L]


But now I'm wanting that if somebody enters admin.example.com that it goes to the https i.e. https://www.example/com/ff/app

(I've only got a www certificate, not one for subdomain, so I guess it must change to the www and not stay as admin for the subdomain.

Hope that make sense.
Cheer
Andrew
andrewpmoore
 
Posts: 9
Joined: Mon Oct 29, 2007 7:41 am

Postby richardk » Wed Jul 15, 2009 12:32 pm

Replace
Code: Select all
RewriteRule .* /ff/app [QSA,PT,L]

with
Code: Select all
RewriteRule .* https://www.example.com/ff/app [R=301,L]


(I've only got a www certificate, not one for subdomain, so I guess it must change to the www and not stay as admin for the subdomain.

Correct.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby andrewpmoore » Wed Sep 23, 2009 7:50 am

Another quick one I'm sure.

I've got
Code: Select all
RewriteRule ^/$ /ff/home/website/home [R,L]

to rewrite my URL when a user enters a blank url (e.g. www.example.com)

What I'm wanting to have happen is 2 things. I want to internally point to www.example.com/ff/home/website/home, but I want the url to stay as www.example.com

Also as I've got sub domains, I only want this redirect to happen for www references and not for the sub domains as they are working as I want.

How would I go about doing this?
Thanks
andrewpmoore
 
Posts: 9
Joined: Mon Oct 29, 2007 7:41 am

Postby richardk » Wed Sep 23, 2009 9:44 am

What I'm wanting to have happen is 2 things. I want to internally point to www.example.com/ff/home/website/home, but I want the url to stay as www.example.com

Then remove the R (Redirect). You may need to add PT.

Also as I've got sub domains, I only want this redirect to happen for www references and not for the sub domains as they are working as I want.

Then match it
Code: Select all
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby andrewpmoore » Thu Sep 24, 2009 3:38 am

Thanks, as always your suggestion was spot on. I needed to add the [PT] for it to work.
Cheers
andrewpmoore
 
Posts: 9
Joined: Mon Oct 29, 2007 7:41 am

Previous

Return to Beginner's Corner

Who is online

Users browsing this forum: Majestic-12 [Bot] and 28 guests

cron