Problem with file name without extension

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

Problem with file name without extension

Postby Clems » Mon Jun 01, 2009 8:24 am

I'm new to mod_rewrite and I'm trying to write a rule for the following url:

http://www.example.com/kb/index?page=ho ... s_overview

to look like the following:

http://www.example.com/home/homebuyers/overview

Please help?

Regards
Clems
 
Posts: 2
Joined: Mon Jun 01, 2009 8:00 am

Postby richardk » Tue Jun 02, 2009 10:39 am

What other c= values are there? Do they always have one underscore?
How many values of page= are there?

For /home/homebuyers_overview
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^([^/]+)/([^/]+)/?$ ./index?page=$1&c=$2 [QSA,L]

(in /kb/.htaccess).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Clems » Tue Jun 02, 2009 12:43 pm

Thanks for the quick answer. In fact, I was able to put the rule together and it works (see code below).
Code: Select all
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/home/(.+)/(.+)?$ /kb/index?page=home&c=$1_$2 [PT]

However, my stylesheets (.css) and javascripts (.js) don't get applied to the resulting JSP page because the application context changed with the rewritten URL and the application can't no longer find the resource folders. For instance, this is how I call my .css and .js from a template hearder file:
Code: Select all
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
   <title>Home Page</title>
     <meta name="description" content="" />
     <meta name="keywords" content="" />
     .
     .

     <link rel="stylesheet" href="<%=Configuration.getStringForKey("appResources")%>/css/global.css" type="text/css" media="screen" charset="utf-8" />
     .
     .
     src="<%=Configuration.getStringForKey("appResources")%>/js/jquery.js" type="text/javascript" charset="utf-8"></script>
     .
     .
</head>


I hope you understand the problem I'm facing. I already figured a way of fixing this by modifying the config file and appending the host name to the resources path. However, I wonder if there is a way to write a RULE that will do both:

1/ Preserving and applying the original context when processing non-request driven resources such as .css and .js

2/ Applying the rewritten URL for requested JSPs only.

Regards
Clems
 
Posts: 2
Joined: Mon Jun 01, 2009 8:00 am

Postby richardk » Tue Jun 02, 2009 4:11 pm

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


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 111 guests

cron