RewriteRule works or not depending on extension

Oh, the strange things mod_rewrite does!

RewriteRule works or not depending on extension

Postby atinar1 » Wed Jul 11, 2007 8:27 am

Hello,
I need to redirect request from a .jnlp url to a .php url. I'm trying this rule:
RewriteRule ^foo\.jnlp foo.php
It doesn't work, but if I try with other extensions instead of jnlp it works. For instance this rule works:
RewriteRule ^foo\.jpg foo.php
(the rest of the .htaccess file is identical, with RewriteEngine on and RewriteBase properly set).

Is it possible that RewriteRule depends on the file/url extension to work?
atinar1
 
Posts: 5
Joined: Wed Jul 11, 2007 8:14 am

Postby richardk » Wed Jul 11, 2007 12:11 pm

Is there something else associated with that extension? I would guess that the other module runs before mod_rewrite so the request never gets to mod_rewrite.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby atinar1 » Thu Jul 12, 2007 10:32 am

I had nothing associated with the jnlp extension. There must be an AddType at the server level but I don't know if there is anything else.
By the way, if I use rules with a fake extension (one without a content-type associated), or no extension at all, such as in:
RewriteRule ^foo\.kk$ foo.php
or
RewriteRule ^foo$ foo.php
should they work?.
Because they don't either..
atinar1
 
Posts: 5
Joined: Wed Jul 11, 2007 8:14 am

Postby richardk » Thu Jul 12, 2007 11:44 am

There's no configuration in mod_rewrite (see the docs) that would exclude an extension. The only thing i can think of is MultiViews. Try adding
Code: Select all
Options +FollowSymLinks -MultiViews

If that doesn't work you'll need to ask your host.

You could test if mod_rewrite gets a chance to process it at all by using
Code: Select all
Options +FollowSymLinks -MultiViews

RewriteEngine On

RewriteRule .* http://www.google.com/? [R,L]

and seeing if you get redirected to Google (it will redirect your whole site (unless you put it in a sub directory)).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby atinar1 » Fri Jul 13, 2007 6:13 am

-MultiViews does not affect.
+FollowSymLinks neither
As I said, mod_rewrite works some times. With the same rule:
RewriteRule ^foo\.(jpg|png|jnlp|kk)$ foo.php
it works when I request:
foo.jpg
foo.png
but it doesn't work when I request:
foo.jnlp
foo.kk

I've already asked our host... I've been trying to get from them an useful answer for more than two weeks, but it seems they only have learned to say "We don't provide support for user written scripts...".
atinar1
 
Posts: 5
Joined: Wed Jul 11, 2007 8:14 am

Postby richardk » Sat Jul 14, 2007 12:26 pm

What happened with the Google redirect? If it didn't redirect the mod_rewrite probably (almost certainly) isn't getting processed. You could try adding
Code: Select all
AddType text/html .jnlp .kk

in case there's some module is catching requests to undefined extensions.

If that doesn't work i don't know what will.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby atinar1 » Sat Jul 14, 2007 5:01 pm

The Google redirect works well.
And adding
Code: Select all
AddType text/html .jnlp .kk
does nothing.

To summarize my last test:
The working directory is /test.
This is the /test/.htaccess file:
Code: Select all
Options +FollowSymLinks -MultiViews
AddType text/html .jnlp .kk
RewriteEngine On
RewriteBase /test/
RewriteRule ^foo\.(jpg|png|jnlp|kk)$ foo.php

When I request foo.jpg or foo.png:
    if the file exists, I get the real file (an image), not the php (the rewrite rule does not work)
    if the file doesn't exists, the rewrite rule works (I get the php)
And when I request foo.jnlp or foo.kk:
    if the file exists I get again the file, with Content Type="application/x-java-jnlp-file" for foo.jnlp and Content-Type="text/plain" for foo.kk (neither the RewriteRule nor the AddType directive work).
    if the file doesn't exists the RewriteRule works neither and I get a 404 error

In conclusion, the AddType directive never works (one problem more) and the RewriteRule only works if there is not a real file behind the url and the type is a "normal" one.
atinar1
 
Posts: 5
Joined: Wed Jul 11, 2007 8:14 am

Postby richardk » Mon Jul 16, 2007 3:08 pm

The Google redirect works well.

Even for .jnlp and .kk paths?

RewriteRule only works if there is not a real file behind the url

It shouldn't do that. Ask your host if they have any special settings.

AddType directive never works

You may not have enough rights/privileges to change it.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby atinar1 » Wed Jul 18, 2007 5:39 am

I'm sorry, I didn't check that, the Google redirect doesn't work for .jnlp nor .kk paths.
It works at usual, returns the .jnlp or .kk file in case it exists or an error 404 otherwise.
atinar1
 
Posts: 5
Joined: Wed Jul 11, 2007 8:14 am

Postby richardk » Wed Jul 18, 2007 7:07 am

Then something seems to be running before mod_rewrite that stops mod_rewrite getting a change to process those requests. I don't know what it could be so you will need to ask your host (or on another forum where someone might have encountered this problem before).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 7 guests

cron