LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache Mod rewrite in Centos 6.2 (https://www.linuxquestions.org/questions/linux-server-73/apache-mod-rewrite-in-centos-6-2-a-4175411211/)

jayakumar01 06-13-2012 07:49 AM

Apache Mod rewrite in Centos 6.2
 
Hi all
I Have a single ipaddress with multiple domain mapped to it .How can i rewrite my url
http://example.in to http://10.200.2.0/home.

http://example.com should point to http://10.200.2.0


example.com - http://10.200.2.0
example.in - http://10.200.2.0/home

acid_kewpie 06-13-2012 08:06 AM

well initially that'll be a mod_proxy issue, not rewrite.

ProxyPass http://example.com http://10.200.2.0
ProxyPassReverse http://example.com http://10.200.2.0

You might well not need any rewriting depending on what the content is.

jayakumar01 06-13-2012 08:29 AM

Thanks for ur reply,

I had tried out these mod_rewwite rules but it never works


RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]


Then i tried out these using proxypass

ProxyPass http://example.in http://10.200.2.0/home
ProxyPassReverse http://example.in http://10.200.2.0/home

when i hit example.in it pointing to http://10.200.2.0

bathory 06-13-2012 09:25 AM

Quote:

Then i tried out these using proxypass

ProxyPass http://example.in http://10.200.2.0/home
ProxyPassReverse http://example.in http://10.200.2.0/home

when i hit example.in it pointing to http://10.200.2.0
You need to do this inside the vhost stanza:
Code:

<VirtualHost *:80>
ServerName example.in
## Add the usual vhost stuff and then ##
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://10.200.2.0/home/
ProxyPassReverse / http://10.200.2.0/home/
</VirtualHost>


jayakumar01 06-13-2012 10:46 AM

Hi


When i had a restart example.com works fine ,example.in delivers 502 proxy error

Whether it neccesssary to have two virtual host since example.in accessing same example.com directory /home folder.whether its easier to achieve my configuration by mod rewrite are else by proxypassReverse


httpd-example.com

Quote:

NameVirtualHost *:80
<VirtualHost *:80>
ServerName example.com

Alias /cms/modules/ /tomcat/webapps/cms/modules
Alias /cms/themes/ /tomcat/webapps/cms/themes
Alias /cms/images/ /tomcat/webapps/cms/images
Alias /cms/css/ /tomcat/webapps/cms/css
Alias /images /tomcat/static/images
Alias /js /tomcat/static/js
Alias /css /tomcat/static/css
Alias /cms/admin /tomcat/webapps/cms/admin
Alias /cms/generated /tomcat/webapps/cms/generated


Alias /php /tomcat/static/php

<Directory /tomcat/static/php>
DirectoryIndex index.php
AllowOverride FileInfo
Options -Indexes +FollowSymLinks -MultiViews
Order allow,deny
Allow from all
</Directory>

<Directory /deployement/tomcat/static>
Allow from all
</Directory>


<Directory /images/airline>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(gif/jpe?g|png|bmp) DEFAULT.gif [NC,L]
</Directory>

JkMount /* worker1
JkMount / worker1
#JkMount /dumile worker1

JkMount /cms/* worker1
JkMount /cms/ worker1
JkMount /cms worker1

JkUnMount /images worker1
JkUnMount /*.jpg worker1
JkUnMount /*.gif worker1
JkUnMount /*.png worker1
JkUnMount /*.css worker1
JkUnMount /*.js worker1
JkUnMount /*.swf worker1
JkUnMount /*.ico worker1


#caching
Header unset ETag
FileETag None
<FilesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header unset Last-Modified
Header set Cache-Control "max-age=7200, must-revalidate"
Header set Cache-Control "public, no-transform"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
</FilesMatch>

#compress content with type html, text, and css
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/*

</VirtualHost>


httpd-example.in

Quote:

<VirtualHost *:80>
ServerName example.in
Alias /cms/modules/ /tomcat/webapps/cms/modules
Alias /cms/themes/ /tomcat/webapps/cms/themes
Alias /cms/images/ /tomcat/webapps/cms/images
Alias /cms/css/ /tomcat/webapps/cms/css
Alias /images /tomcat//static/images
Alias /js /tomcat/static/js
Alias /css /tomcat/static/css
Alias /cms/admin /tomcat/webapps/cms/admin
Alias /cms/generated /tomcat/webapps/cms/generated


Alias /php /tomcat/static/php

<Directory /tomcat/static/php>
DirectoryIndex index.php
AllowOverride FileInfo
Options -Indexes +FollowSymLinks -MultiViews
Order allow,deny
Allow from all
</Directory>

<Directory /deployement/tomcat/static>
Allow from all
</Directory>



## Add the usual vhost stuff and then ##
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://10.200.2.0/home/
ProxyPassReverse / http://10.200.2.0/home/



<Directory /images/airline>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(gif/jpe?g|png|bmp) DEFAULT.gif [NC,L]
</Directory>

JkMount /* worker1
JkMount / worker1
#JkMount /dumile worker1

JkMount /cms/* worker1
JkMount /cms/ worker1
JkMount /cms worker1

JkUnMount /images worker1
JkUnMount /*.jpg worker1
JkUnMount /*.gif worker1
JkUnMount /*.png worker1
JkUnMount /*.css worker1
JkUnMount /*.js worker1
JkUnMount /*.swf worker1
JkUnMount /*.ico worker1


#caching
Header unset ETag
FileETag None
<FilesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header unset Last-Modified
Header set Cache-Control "max-age=7200, must-revalidate"
Header set Cache-Control "public, no-transform"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
</FilesMatch>

#compress content with type html, text, and css
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/*

</VirtualHost>

bathory 06-13-2012 11:51 AM

Hi,

The 502 error you get could be due to a variety of reasons. So take a look at both apache and the backend server's logs.
I guess the backend is a tomcat server, so keep in mind that if you use a reverse proxy configuration like the one I've posted above, there is no need to for anything related to mod_jk. You should choose only 1 method of connecting to tomcat, either by mod_jk, or through a reverse proxy setup.
Also the various Alias, <Directory ...> etc, are useless in the latter case

Regards

jsaravana87 06-13-2012 12:05 PM

You can achieve these by mod _rewrite rather than ProxyPassReverse

<VirtualHost *:80>
ServerName example.in
#/**added this**/
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/home(.*)$
RewriteRule ^/(.*)$ http://10.200.2.0/home$1 [R,L]
#/**end**/
</VirtualHost>


All times are GMT -5. The time now is 03:46 AM.