我在ubuntu 10.4上使用apache2 + tomcat。我有web應用監聽8080如何正確mod_rewrite
Tomcat服務器上運行的 「http://內部:8080/DIR /名稱 - privatewebapp /」
的 「http://內部:8080/DIR /名稱 - publicwebapp /」
面向外部的Apache服務器正在代理域的請求。
我想重新映射「子域」到「domain.com/subdomain」,所以任何其他請求將被代理到相應的路徑/ webapp的
web.john-doe.domain.com ---> www.domain.com/web/john-doe
http://www.john-doe.com ---> www.domain.com/web/john-doe
http://www.foo-bar.com ---> www.domain.com/web/foo-bar
我不能使它與mod_rewrite的單獨工作。我一直在尋找到 的mod_proxy,mod_proxy_ajp的,和mod_rewrite的
我想服務器
- 抓鬥從域的子域
- 確保子域名是不是WWW,W或WW
- 檢查目錄是否實際存在於「www.domain.com」,然後重寫
- 如果該目錄不存在,則將其保留爲野區域
- 最後,如果導演Ÿ存在實際重寫
我檢查了幾個環節,並研究了http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html
這是沒有成功的教程。
我跟着這個 illumin-it.servehttp.com/wordpress/2012/01/redirecting-to-as-using-apache/ 有一點成功。
但是,我希望服務器通過重寫和代理來執行此操作,而無需爲每個子域編輯虛擬主機。
這裏是我更新的虛擬主機文件
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName www.domain.com
ServerAlias www.domain.com domain.com *.domain.com
RedirectPermanent/http://www.domain.com
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase/
# Prevent looping this rule
# RewriteCond %{ENV:REDIRECT_STATUS} !200
# RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
# RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9.-]+).domain.com$ [NC]
# RewriteRule (.*) /%2/$1 [L]
# change the "." in the path to "/"
# RewriteRule ^(.*)\.(.*)/(.*)$ /$1/$2/$3 [L]
#redirect domain.com to www.domain.com
RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteRule^http://www.domain.com%{REQUEST_URI} [R=301,NC]
</IfModule>
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# ErrorLog /var/log/apache2/webapp_error.log
# LogLevel warn
# CustomLog /var/log/apache2/webapp_access.log combined
ProxyPass/ajp://localhost:8009/
ProxyPassReverse/ajp://localhost:8009/
# ProxyPass /user/ http://localhost:8080/user/privatewebapp/
# ProxyPassReverse /user/ http://localhost:8080/user/privatewebapp/
#
# ProxyPass /publicweb/ http://localhost:8080/dir/publicwebapp/
# ProxyPassReverse /publicweb/ http://localhost:8080/dir/publicwebapp/
#
# ProxyPass /http://localhost:8080/dir/publicwebapp/
# ProxyPassReverse/http://localhost:8080/dir/publicwebapp/
ServerName www.domain2.com
ProxyRequests Off
ProxyPreserveHost On
RewriteEngine On
RewriteCond %{HTTP_HOST} ^dir/publicwebapp$ [NC]
RewriteRule ^(.*)$ http://www.domain2.com/$1 [R=301,L]
<Location/>
Order deny,allow
Allow from all
RedirectMatch ^/$ /dir/publicwebapp/
ProxyPass ajp://localhost:8009/
ProxyPassReverse ajp://localhost:8009/
</Location>
</VirtualHost>
我也試過...... http://httpd.apache.org/docs/2.0/rewrite/rewrite_guide.html
假設www.username.host.com/anypath內部映射到www.host.com/home/用戶名/任何路徑
作爲網站的應用程序與Java服務器創建,我相信mod_rewrite本身並不工作。
虛擬用戶主機
RewriteCond %{HTTP_HOST} ^www\.[^.]+\.host\.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^www\.([^.]+)\.host\.com(.*) /home/$1$2
謝謝你許多。這真的讓我走向正確的方向。我意識到我需要mod_proxy,mod_proxy_ajp和mod_rewrite組合。我的應用程序託管在端口8080上的單個Apache Tomcat上 – bay