Clear RESTful URLs in OJS3?

Following the FAQ and other threads here, I’ve set restful_urls = On and put rewrite rules into my .htaccess. With the latest bleeding-edge OJS, this doesn’t seem to work; the home page loads, but CSS and XHR fail to load, and links to specific journals break as well. (“The requested URL …ojs_dev/index.php/test was not found on this server.”)

Is this a regression, or am I missing some step?

[I did restart Apache, and I get no errors, so it’s not a syntax problem…]

Hi @crism,

That probably hasn’t been tested for a while; I’ve filed it for a look before the release of OJS 3.0:

Regards,
Alec Smecher
Public Knowledge Project Team

Thanks, @asmecher

Revisiting this, now that the GitHub issue is closed… still no luck.

I set restful_urls = On. I used a local .htaccess as recommended in the FAQ:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>

I restarted Apache and cleared my browser cache.

The OJS home page loads, but CSS does not; it is unstyled. Links to register, login, or view specific journals come up 404: visiting a test journal at .../ojs_dev/test gives the message, “The requested URL …/ojs_dev/index.php/test was not found on this server.” Visiting .../ojs_dev/index.php/test directly does work to get to the test journal home page; however, CSS is still not loaded properly.

The Apache error log shows no messages after restart; the access log does show the 404 responses.

It looks like the rewrite rule is being observed, so that /test is redirected to /index.php/test, but for some reason, PHP is not then being properly dispatched to handle that request. When I use a phpinfo() test page and append extra path to that, it shows up properly:

REQUEST_URI: /ojs_dev/test.php/foo/bar/baz
SCRIPT_NAME: /ojs_dev/test.php
PATH_INFO: /foo/bar/baz
PATH_TRANSLATED: /var/www/html/foo/bar/baz

I’m prepared to just drop this and tell our users that they just have to live with the ugly URLs, but if anyone has any suggestions, I’d love to hear them.

Interesting; if I change the rewrite rule to use test.php instead, which is simply a call to phpinfo(), I get the same behavior: a 404 error that .../ojs_dev/test.php/test is not found. Visiting .../ojs_devtest.php/test directly works. So it’s definitely something with the way Apache is dispatching the request after the rewrite rule fires, rather than a problem with OJS itself. Hrm.

I solved the problem. I think it was due to OJS not running in the server root; e.g., instead of http://example.com/index.php, it was http://example.com/ojs_dev/index.php. Adding a RewriteBase directive fixed it:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteBase /ojs_dev/
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>

Hi @crism,

Thanks, glad it’s worked out!

Regards,
Alec Smecher
Public Knowledge Project Team

I have this problem, too, but I did not understand how to fix it. Which file should be modified?