Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Issues in Setting Url path in Mod Rewrite .

httpd and .Htaccess .


Arjun Kochhar

1:53 pm on Dec 1, 2009 (gmt 0)

5+ Year Member

Hi ,
The aim is to convert the dynamic url to a static one , using Apache 2.2x and Tomcat Application Server,OS: Windows
Eg: [localhost...]
Should be accessed by [localhost...] /jsp/Anghiti/6/

what i'd like to know is :
1.How do I make httpd.conf file find .htaccess file ?
2.How to set the Url path for STEP 1?
3.IF everything (URL rewriting , Custom error page display , Redirecting) works with "ONLY APACHE " Why does tomcat in between cause haywire ?
For this I have the httpd.conf file consisting of the following :

DocumentRoot "C:/Apache/Tomcat5.0/webapps/foodportal/jsp"

RewriteEngine On
RewriteLog "C:/Apache2.2/logs/rewrite.log"
RewriteLogLevel 3
RewriteRule /([\w-.\s]+)/([0-9]+)/?$ /FoodSourceDetailsResult.jsp?RestaurantName=$1&RRowNo=$2 [NC,L]
<Directory "C:/Apache/Tomcat5.0/webapps/">
Options FollowSymLinks
AllowOverride none
Order deny,allow
Deny from all
This gives the Resource not found Error 404 .

Changing the Rewrite Rule to RewriteRule /([\w-.\s]+)/([0-9]+)/?$ [localhost...] [NC,L]

With this rule the dynamic page is displayed when I enter [localhost...] in the address bar , But the Server does an implicit Redirect 302 and the Url is changed back to [localhost...] hence getting a partial solution .
While it should show [localhost...] .
Both the configurations were in httpd.conf file .


10:22 pm on Dec 1, 2009 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

The server doesn't "do an implicit redirect," some *code* on the server invokes the redirect.

You need to find that code.

The problem with the internal rewrite variant of your rule (the one you want to use) may be that you need to add the [PT] flag, so that the output from mod_rewrite can be passed to your back-end as a URL, not a filepath.

I'd also suggest that you start-anchor that rule pattern, to avoid unexpected problems in the future.


Arjun Kochhar

8:25 am on Dec 2, 2009 (gmt 0)

5+ Year Member

Thanks jim , adding the [PT] flag made it work perfectly .

Arjun Kochhar

10:07 am on Dec 4, 2009 (gmt 0)

5+ Year Member

hey again ,

After putting the [PT] flag the rewrite worked fine , and as you mentioned not using the start anchor did cause a few unexpected problems , after putting the start anchor there seem to be issues wrt loading of .css and .js files.

why these problem are because its searching for the .css , .js and image files from

while it should look from [localhost...]

i tried to solve this issue using the following rules (in vain) :

RewriteRule ^/foodportal/jsp/([\w-.\s]+)/([0-9]+)/?$ /foodportal/jsp/FoodSourceDetailsResult.jsp?RestaurantName=$1&RRowNo=$2 [NC,PT]
RewriteCond %{REQUEST_FILENAME} ^(.+)\.css$
RewriteRule ^(.+)$ /foodportal/jsp$1 [NC,PT]
RewriteCond %{REQUEST_FILENAME} ^(.+)\.js$
RewriteRule ^(.+)$ /foodportal/jsp$1 [NC,PT]

RewriteRule ^/foodportal/jsp/[\w-.\s]+/([\w-.\s]+)?$ [localhost...] [NC,R=301]


4:27 pm on Dec 4, 2009 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Instead of adding more rules, you may simply need to exclude .css, .js, and .gif/jpg/png/ico URLs from being rewritten by the recently-added rule. I can't tell, because I cannot pretend to understand your site well, given only what's in this thread and the time I have to read about it.

Another common problem that arises when rewriting URLs is that if the links to included objects on the page are page-relative, then the browser will incorrectly resolve those relative links to canonical URLs, and request incorrect URLs. The cure is to use server-relative links or canonical URL links. That is, .css, .js and image links should start either with a slash and the full server filepath, or with "http://example.com/" plus the full server filepath. Example: Use <img src="/images/logo.gif"> or <img src="http://example.com/images/logo.gif">, not <img src="images/logo.gif">

Take a look at the request from your pages using a server heasers checker (the Live HTTP Headers add-on for Firefox is good) and take a hard look at your server error log. The correct cure for the problem depends on whether the included-object URL is correct but is being incorrectly rewritten, or the included-object URL is incorrect because rewriting the page URLs has resulted in incorrect object links on the pages.



Featured Threads

Hot Threads This Week

Hot Threads This Month