logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: JkMount and rewriting
Author
yuvi2288



Joined: 17 Aug 2010
Posts: 1

PostPosted: Wed 18 Aug '10 6:32    Post subject: JkMount and rewriting Reply with quote

Hello all,

I am doing my project in jsp. I need to use mod_rewrite concept in my project in order to view public user profile as in facebook.

i.e. I wrote the code to retrieve the user's public info from the database by passing userid as an argument as follows.

http://localhost/myproject/user/publicprofile.jsp?userid=username

But I have to rewrite the above to

http://localhost/myproject/username for simplicity.

I found that it can be done by using mod_rewrite.
But mod_rewrite works only in apache server not in tomcat server.
So I integrate Apache2.2 with Tomcat 6.0.29 using the tomcat connector.

I configured httpd.conf as follows:

Code:



ServerRoot "C:/xampp/apache"


LoadModule rewrite_module modules/mod_rewrite.so
LoadModule autoindex_color_module modules/mod_autoindex_color.so


ServerName localhost:80


DocumentRoot "C:/xampp/htdocs"


<Directory "C:/xampp/htdocs">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all

</Directory>


<IfModule dir_module>
    DirectoryIndex index.php index.pl index.cgi index.asp index.shtml index.html index.htm \
                   default.php default.pl default.cgi default.asp default.shtml default.html default.htm \
                   home.php home.pl home.cgi home.asp home.shtml home.html home.htm
</IfModule>


<Directory "C:/Apache/apache-tomcat-6.0.29/webapps/user">
Order allow,deny
Allow from all
</Directory>

LoadModule jk_module "C:/xampp/apache/modules/mod_jk.so"
JkWorkersFile "C:/Apache/apache-tomcat-6.0.29/conf/workers.properties"
JkLogFile "C:/Apache/apache-tomcat-6.0.29/conf/from_apache_mod_jk.log"
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# Send servlet for context /examples to worker named ajp13
JkMount /examples ajp13
# Send JSPs for context /examples/* to worker named ajp13
JkMount /examples/* ajp13

# Send servlet for context /user to worker named ajp13
JkMount /user ajp13
# Send JSPs for context /user/* to worker named ajp13
JkMount /user/* ajp13



For testing the mod_rewrite, I code three files as follows:

test.jsp

Code:
<html>
<body>
<form action = "form.jsp" method="get">
Name : <input type="text" name="name"/><br/>
<input type="submit" value="ok"/>
</form>
</body>
</html>


form.jsp

Code:
<html>
<body>
<%

String name = request.getParameter("name");
out.println(name);

%>
</body>
</html>


.htaccess file

Code:
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /user/form.jsp?name=$1 [L]


I saved the three above mentioned files in C:\Apache\apache-tomcat-6.0.29\webapps\user

when I execute the code in browser as

http://localhost/user/form.jsp?name=yuvi

it outputs the given name, but , when I use
http://localhost/user/yuvi.html

it didn't work (i.e., the .htaccess file is not accessed I think so).

When I tried the above mentioned sample in php by saving the three php files in C:\xampp\htdocs\test, I got the desired output and .htaccess works.

But I don't know why it does not work in jsp!!

Hope that you will understand my problem. Help me please.

Thanks and Regards,

yuvi

Modnote: removed unneeded stuff from httpd.conf code. We know standard settings. Update: Changed title
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7355
Location: Germany, Next to Hamburg

PostPosted: Thu 26 Aug '10 16:11    Post subject: Reply with quote

you need to set the pass through flag "PT" for the rewrite
rules.

See also "pass through" in

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

Also: if you are using VirtualHosts, you need to put the JkMount into
the VirtualHosts.

Let us know, if that works.
Back to top


Reply to topic   Topic: JkMount and rewriting View previous topic :: View next topic
Post new topic   Forum Index -> Apache