Forum Moderators: phranque

Message Too Old, No Replies

Changing dynamic to static URLs - Not Working, Could Any one Help me

Changing dynamic to static URLs - Not Working

         

Raj123

8:49 pm on Oct 17, 2006 (gmt 0)

10+ Year Member



We are in the process of making the site user-friendly/search engine friendly for a new site which has got lot of dynamic URLs.
I am using these rules inside the Virtual Host Directive.
When I use the Equivalent Dynamic URL, The page got displayed. The URL in the browser did not change.

How ever when I am using the equivalent static URL in the browser. I am getting the 404. I could not figure out the problem. Could any one help me. Help is highly appreciated. Thanks in advance

RewriteRule ^/appmanager/bg/main/([^/]+)/?$ /appmanager/bg/main?_nfpb=true&_pageLabel=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /appmanager/bg/main?product=?_nfpb=true&_pageLabel=([^\ ]+)\ HTTP/
RewriteRule ^/appmanager/bg/main$ [%{HTTP_HOST}...] [R=301,L]

jdMorgan

10:58 pm on Oct 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have any other rewriterules in that file that work?
If not, have you enabled mod_rewrite and turned on the rewrite engine?
Have you tried a simple test, like this:

RewriteRule ^/foobar\.html$ http://www.example.com/some_page_that_exists.html [R=301,L]

to see if mod_rewrite is working at all?

Jim

Raj123

3:55 pm on Oct 18, 2006 (gmt 0)

10+ Year Member



Jim thanks a lot for you feedback. It helped a lot to figure out the problem.

The Mod Rewrite module was enabled, However I had made the entry for RewriteLogLevel and RewriteEngine directives outside the Virtualhost directive in the config file, the rewrite engine was not working due to that. Now the Rewrite engine is working after moving the directive inside the Virtualhost directive. I had done stupid mistake in the RewriteCond rule, I removed "product=?" from the rule. The Rules I am using following rules

RewriteRule ^/appmanager/bg/main/([^/]+)/?$ /appmanager/bg/main?_nfpb=true&_pageLabel=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /appmanager/bg/main?_nfpb=true&_pageLabel=([^\ ]+)\ HTTP/
RewriteRule ^/appmanager/bg/main$ [%{HTTP_HOST}...] [R=301,L]

When I use the following static URL
[localhost...]
I am getting the 404 with out the R flag in the first rule. When I added R flag in the first rule, The static URL works.

When I use the following dynamic url.
[localhost...]

the page got displayed. However Rewrite log shows that Rewrite Condition is not matched.

When the search engine making the request with the dynamic url. The server will send the 302 Response with the new static url, then the search engine will make request again with the static URL and the request is served. When I was trying to simulate this condition through the browser using the dynamic url I did not see any change in the URL in the browser address bar. I could not figure out the problem. Jim could you kindly help me on this. Thank you son much.

jdMorgan

5:21 pm on Oct 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Look at your server error log after requesting the static URL. It is likely that the filepath that the rule is rewriting to does not agree with the actual filepath of the file. This may be caused if your DocumentRoot directive is incorrect or does not contain the full path to the directory in which appmanager resides.

You may wish to correct the DocumentRoot path if it is really wrong, or to use mod_rewrite's RewriteBase directive to "adjust" mod_rewrite to recognize and use the correct filepath.

The server error log should make the problem clear.

Jim

Raj123

1:51 pm on Oct 19, 2006 (gmt 0)

10+ Year Member



Hi Jim
Thank you so much for your timely response. The actual files are residing in the weblogic server. The apache server is only serving the request, no files of the application resides in the appache. When I use the static url, the rewrite engine makes the local path to
/appmanager/bg/main

and the DocumentRoot to

C:/tomcat/Apache2/htdocs/appmanager/bg/main.

In the Documnent root directory i used the same rules using the .htacess file. In this case the URL in the browser looks like this.

[localhost...]

Could you help me whether i am in the right direction, your valuable help is highly appreciated. Thanks you so much.

Raj

jdMorgan

3:49 pm on Oct 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If these files reside on a different server, you'll need to proxy the rewritten request over to that server using the [P] flag of mod_rewrite, or by defining a new Alias in httpd.conf so that rewritten URLs get proxied to the back-end.

I can't provide much more info, as I don't use Tomcat myself. You may be able to get better help from Tomcat user forums or the Tomcat or mod_jk support sites.

Jim

Raj123

5:49 pm on Oct 19, 2006 (gmt 0)

10+ Year Member



Jim Thanks a lot for your feedback.
The Apache Installed under the C:\tomcat folder. There is no tomcat server used. I really sorry for the inconvenience caused.

Raj123

2:01 pm on Oct 20, 2006 (gmt 0)

10+ Year Member



Jim

After adding the proxy flag, the first rule is working. Thanks you so much for your valuable suggestion. Since I am new to appache, I really need you help on this. The rules I am using are below.

RewriteRule ^/appmanager/bg/main/([^/]+)/?$ /appmanager/bg/main?_nfpb=true&_pageLabel=$1 [L,P]
RewriteCond %{THE_REQUEST}![A-Z]{3,9}\ /appmanager/bg/main?_nfpb=true&_pageLabel=([^\ ]+)\ HTTP/
RewriteRule ^/appmanager/bg/main$ [%{HTTP_HOST}...] [R=301,L]

I am getting a not matched condition when the rewriteCond is not negated, I negated the pattern to see both the rules working. When i looked in to the log file. It is looping, This happens when i use the dynamic url in the browser.

[localhost...]

Could you please help me how to avoid the looping. Thanks a lot in advance.

Raj

jdMorgan

2:18 pm on Oct 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You forgot to escape the "?" in the RewriteCond pattern. If a "?" in a pattern is not escaped, then it means that the preceding character may occur zero or one time.

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /appmanager/bg/[b]main\?_nfpb[/b]=true&_pageLabel=([^\ ]+)\ HTTP/

The negation was the cause of the loop, and since that's not logically what you want, it was a bad test that led to the further problem of looping.

Jim

Raj123

5:03 pm on Oct 20, 2006 (gmt 0)

10+ Year Member



Hello Jim.

Thanks you so much for your timely and valueable help. I have changed the second rule as the following.

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /appmanager/bg/main\?_nfpb=true&_pageLabel=([^\ ]+)\ HTTP/
RewriteRule ^/appmanager/bg/main$ [%{HTTP_HOST}...] [R=301,L]

Now I am getting the looping problem for both static url and dynamic url. Could you please kindly help me where i am going wrong. Is there any other configuration parameter i need to look for. Your help would be more appreciated. Thanks a lot.

Raj

jdMorgan

4:27 pm on Oct 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm pretty much out of ideas. There is probably a simple answer, and it might be obvious if I was sitting next to you, looking over your shoulder as you tested and used FTP or SSH to navigate the directory structure of your site. That's a problem with a forum medium -- It's impossible to describe the server setup thoroughly without spending a month doing it. Also, as I stated, I don't use Tomcat myself, so I can only speak in generalities.

If the proxy method is looping the only other thing I can recommend trying is to use the [PT] flag instead of the [P] flag, and see if that works:


RewriteRule ^/appmanager/bg/main/([^/]+)/?$ /appmanager/bg/main?_nfpb=true&_pageLabel=$1 [PT,L]

Since this will NOT invoke a new HTTP request, it should stop the looping. BUt it still may not work as far as rewriting the URL.

Jim

Raj123

1:10 pm on Oct 23, 2006 (gmt 0)

10+ Year Member



Hello Jim,

Thanks you so much for your great help. I understand the document root what i have mentioned is misleading, I would like mention that there is not tomcat server running. The Apache server is installed under the c:\tomcat directory. I really sorry to bother you again. When i use the PT flag I am getting the message as "Your browser sent a request that this server could not understand.". Is there any other place in the config file I need to look in. You help is highly appriciated. Thanks a lot in advance.

Raj123

1:31 pm on Oct 25, 2006 (gmt 0)

10+ Year Member



Hello Jim.

Thanks a lot for your valuable feedback and help.
There was some problem in my apache server instance. Now the rewrite rules are working after using the PT flag in the first rule. I thank you so much for all your help

Raj.

jdMorgan

2:51 am on Oct 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Very good news!

Jim