mod_rewrite misconfiguration

Hi,

I’m fighting since yesterday with an odd issue with my brand new server. I just migrated to:

  • Debian 7
  • Apache/2.2.22 (Server built: Dec 23 2014 22:48:29)
  • PHP 5.4.36-0+deb7u3 (phpinfo here)

I’m working in a mOJO installation (multiOJS with symlinks to a single OJS 2.4.5 code).

The problem is that now, after migration, I’m not able to visit “/index” in all the journals that own an specific domain.

Here you can see the error: http://studiaaurea.es/index

This is a simplified version of my web-root .htaccess (showing only global and one domain rules):

# From: http://pkp.sfu.ca/support/forum/viewtopic.php?f=8&t=3546
# Extended: http://pkp.sfu.ca/support/forum/viewtopic.php?f=2&t=2616
# Recreated on: 20150312-0011

AcceptPathInfo On    
RewriteEngine On    
RewriteBase /
RewriteRule ^robots.txt$ /robots.txt.php

# Rules for magazine journalOwnDomain (folder /htdocs/ojs-journalTag)
RewriteRule ^journalTag$ journalTag/
RewriteRule ^journalTag/(.*)$ ojs-journalTag/index.php/journalTag/$1 [L,QSA]
RewriteRule ^ojs-journalTag/journalTag/(.*)$ ojs-journalTag/index.php/journalTag/$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ojs-journalTag/(.*)$ ojs-journalTag/index.php/index/$1 [L]

RewriteCond %{SERVER_NAME} ^journalOwnDomain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ journalTag/$1 [L]

RewriteCond %{SERVER_NAME} ^www.journalOwnDomain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ journalTag/$1 [L]

If you visit “http://journalDomain.com/index” you will get a 404 error… while the rest of urls work perfectly.

This is the mod_rewrite log (LogLevel 2) after visit “/index”. Yes… just show a single line:

37.133.118.95 - - [13/Mar/2015:00:02:42 +0100] [journalOwnDomain.com/sid#7fe1bd7f1d60][rid#7fe1b85df0a0/subreq] (1) [perdir /home/ojs/htdocs/] pass through /home/ojs/htdocs/index.php

Notice that is redirecting to “/home/ojs/htdocs/index.php”
instead of “/home/ojs/htdocs/ojs-journalTag/index.php”

Any suggestion to follow digging? I’m really stacked with this and it’s making me crazy…

Thanks a lot for your time,
m.

Maybe a silly question

Shouldn’t be the link http://studiaaurea.es/index.php?

Thanks Antonio.

As far as I see, the link is ok. Is not as simple as missing the .php extension… :wink:

The physical structure behind my server is described here:
http://pkp.sfu.ca/support/forum/viewtopic.php?f=8&t=7578#p29284

If I understand my own mod_rewrite rules (and this is a big IF :-P), when you visit http://studiaaurea.es/index.php you are redirected as follows:
http://studiaaurea.es/ojs-studiaaurea/studiaaurea/index.php
→ And then to the physic file at: /home/ojs/htdocs/ojs-studiaaurea/index.php

If you visit http://studiaaurea.es/about RewriteRules will redirect perfectly to:
http://studiaaurea.es/ojs-studiaaurea/index.php/studiaaurea/about
(“htaccess/ojs-journalTag” folder with “journalTag/about” as querystring)

Crazy thing is It didn’t happens when you go to “http://studiaaurea.es/index

Cheers,
m.

Sorry Marc.

What I meant is index.php worked.

Others non existing pages doesn’t work either:
http://studiaaurea.es/fake
http://studiaaurea.es/wrong

Why should studiaaurea/index work? In our case http://revistas.inia.es/index, it doesn’t work either.

Hi,

I didn’t check the code, but /index is like /manager an OJS verb.
The equivalence without mod_rewrite will be http://revistas.inia.es/index.php/index

Is bumpping an allowed practice in the new forum? :flushed:

Beware of a change in the way REQUEST_FILENAME is interpreted between Apache < 2.2 and Apache 2.2+.

http://pkp.sfu.ca/bugzilla/show_bug.cgi?id=8797#c9

Is it possible you are at 2.2+ with the new server and were previously working with an earlier version?

1 Like

Thanks a looot, Clinton.

Yes, this is just the scenario.

Looking for a fix, I pass through the REQUEST_FILENAME modification, but now you point… seams obvious that must be related.

The easy fix you suggest in bugstrack (use “%{DOCUMENT_ROOT}%{REQUEST_FILENAME}” instead of “%{REQUEST_FILENAME}”) don’t work for me… hopefully not related with my symlinked environment.

When I try your fix, I got too much nested redirections, due “!-f” condition is not evaluated properly… But thanks a lot for your comment. I’m confident now I’m in the right way.

I will do some testing with a not used domainname and “LogLevel Debug” to see what happens…

Cheers,
m.

Confirm that your DocumentRoot has the trailing /, or add the slash separator between DOCUMENT_ROOT and REQUEST_FILENAME. That difference bit me a few times.

1 Like

No luck :cry:

DocumentRoot includes the trailing slash, and i tested adding and an slash between both apache variables and it still fails.

Two questions raise to me:

a) Why it happens with /index, but not with /login or /manager?
I mean, my mod_rewrite rules work differently with “/index”… and got stuck in /htdocs folder instead of going to /htdocs/ojs-journalTag one.
b) Any suggestion about how to debug a big .htaccess in a production server?
My .htaccess, with rules for all my journals, is now close to 500 lines. :blush:

I made a test with an secondary domain and with an simple new .htaccess and seams that /index is working fine there… so I’m starting to think the problem is related with a former rule that catches the url and redirects to DocumentRoot instead of letting those rules do the right job:

Thanks a lot for your help!!
m.

Former questions are still, in the air… but let me update and simplify the problem.

I did a replica of my production server with just one journal and a very simplified htacces, and the issue persist:

This is the new htaccess:

AcceptPathInfo On    
RewriteEngine On
RewriteBase /
RewriteRule ^robots.txt$ /robots.txt.php

# Rules for magazine ada
RewriteRule ^pep$ pep/
RewriteRule ^pep/(.*)$ ojs-pep/index.php/pep/$1 [L,QSA]
RewriteRule ^ojs-pep/pep/(.*)$ ojs-pep/index.php/pep/$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ojs-pep/(.*)$ ojs-pep/index.php/index/$1 [L]

RewriteCond %{SERVER_NAME} ^ada.uab.cat
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ pep/$1 [L]

And this is the virtual host:

<VirtualHost *:80>
        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                # AllowOverride None
                # Order allow,deny
                # allow from all

                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/ada-test-error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/ada-test-access.log combined
</VirtualHost>

Journal folder is in “/var/www/ojs-pep” and journalTag is “pep”

Changing “{REQUEST_FILENAME}” for “%{DOCUMENT_ROOT}%{REQUEST_FILENAME}” (with or without slash) didn’t help.

I think I didn’t miss nothng…

Thanks again,
m.

Sounds like it is time to add a high value for your LogLevel. Rewrite rules behave a bit differently in .htaccess files than in the VirtualHost section; perhaps one of the rules is getting called via subrequest when you’re not expecting it to be called.
http://httpd.apache.org/docs/trunk/rewrite/tech.html#InternalAPI

1 Like

It took me a week, but I found it !! :fireworks:
Thanks you all for your help.

I recognize that I still don’t understand why it happens… (it worked and still works fine in my old server with my old apache) but if I remove the index.php in my web-root folder (/htdocs/index.php) my mod_rewite rules worked again. Looks like in the new serve “/index” is redirected to “index.php”. :hushed:

I reviewed my apache config, and every htaccess I could find and I’m not able to recognize the responsible of the redirection.

The offending “index.php” basically include a set of rules to redirect properly, but same work could be done with mod_rewrite.

Thanks again,
m.

This is my best guess right now:
http://httpd.apache.org/docs/2.2/mod/mod_dir.html#fallbackresource

Did you know about this new directive?