homepage Welcome to WebmasterWorld Guest from 54.205.254.108
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Issues in Setting Url path in Mod Rewrite .
httpd and .Htaccess .
Arjun Kochhar




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

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 :

STEP 1.
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
</Directory>
This gives the Resource not found Error 404 .

STEP 2.
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 .

 

jdMorgan




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

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.

Jim

Arjun Kochhar




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

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

Arjun Kochhar




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

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
[localhost...]

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]

jdMorgan




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

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.

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved