OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



HOW-TO: use mod_rewrite to get rid of index.php in the url

Are you an Editor, Author, or Journal Manager in need of help? Want to talk to us about workflow issues? This is your forum.

Moderators: jmacgreg, michael, vgabler, John

Forum rules
This forum is meant for general questions about the usability of OJS from an everyday user's perspective: journal managers, authors, and editors are welcome to post questions here, as are librarians and other support staff. We welcome general questions about the role of OJS and how the workflow works, as well as specific function- or user-related questions.

What to do if you have general, workflow or usability questions about OJS:

1. Read the documentation. We've written documentation to cover from OJS basics to system administration and code development, and we encourage you to read it.

2. take a look at the tutorials. We will continue to add tutorials covering OJS basics as time goes on.

3. Post a question. Questions are always welcome here, but if it's a technical question you should probably post to the OJS Technical Support subforum; if you have a development question, try the OJS Development subforum.

Re: HOW-TO: use mod_rewrite to get rid of index.php in the url

Postby robinhood1362 » Mon Feb 23, 2009 3:29 pm

Hi MJ
You said the "clean url" thing is getting into core in hopefully near future (may it come sooner).
But on a technical note again, the last modification to rewrite rule you proposed (RewriteRule ^(.*)$ index.php/jirc/$1 [QSA,L]) does nothing in terms of removing, in this example, "jirc" from the url (I tested that on my OJS installation). I have already set up the journal with the "index.php" in the url, and google indexes the pages nicely, however, I could use some rewrite rule before the next version of OJS with built-in clean urls is out, and have some time before google indexes pages again.
And thanks Dr. Saghaei for mentioning those nice tips on Rewrite, I tested my server settings; they're OK.
Regards
robinhood1362
 
Posts: 31
Joined: Sat May 24, 2008 3:27 pm

Re: HOW-TO: use mod_rewrite to get rid of index.php in the url

Postby mj » Tue Feb 24, 2009 10:02 am

Hi Sina,

The code for making OJS URLs fully RESTful (removing index.php from both links and via mod_rewrite) is already in the current CVS branch, and will be in the next release of OJS, roughly scheduled for April.

As for the RewriteRule to redirect an entire OJS installation to a particular journal, if you're having issues, then it may have to do with your server set-up. I can confirm that it works on my (fairly common) Mac OSX server.

Make sure you're not adding the Rewrite Rule, but rather modifying the last line to reflect the journal you want to use. eg. the entire rewrite set should look like:

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


Where "JOURNAL" is the short name of the journal you want to short-cut to. This way, URLs for eg. http://localhost/issue/current will be redirected to http://localhost/index.php/JOURNAL/issue/current. I don't believe Google's ability to index an OJS site is affected by RESTful URLs or not, but I'd be curious to see some evidence to the contrary.

Hope this helps,
MJ
mj
Site Admin
 
Posts: 304
Joined: Fri Mar 26, 2004 9:32 am
Location: Toronto, Canada

Re: HOW-TO: use mod_rewrite to get rid of index.php in the url

Postby arachne » Fri Nov 13, 2009 10:58 am

Hi - I am having trouble getting the mod_rewrite to work on OJS 2.2.3 - we trasnferred to a new server with the new build (Synergies). The mod_rewrite worked fine in the old version (2.1.1). Just wondering if there's some code change in 2.3 that I should try instead?

mj wrote:
The code for making OJS URLs fully RESTful (removing index.php from both links and via mod_rewrite) is already in the current CVS branch, and will be in the next release of OJS, roughly scheduled for April.


cheers,
Jenea
arachne
 
Posts: 52
Joined: Sun Feb 11, 2007 3:46 pm
Location: Vancouver

Re: HOW-TO: use mod_rewrite to get rid of index.php in the url

Postby jmacgreg » Tue Nov 17, 2009 12:08 pm

Hi Jenea,

Just double-checking that this thread has been resolved as per this weekend's pkp-hosted discussion.

Cheers,
James
jmacgreg
 
Posts: 4181
Joined: Tue Feb 14, 2006 10:50 am

Re: HOW-TO: use mod_rewrite to get rid of index.php in the url

Postby arachne » Tue Nov 17, 2009 1:06 pm

Thanks James, yes, we got that solved - it was a server-side issue (enabling .htaccess rules to work) for those who might wonder. The regular mod-rewrite from this thread works fine.

cheers,
Jenea
arachne
 
Posts: 52
Joined: Sun Feb 11, 2007 3:46 pm
Location: Vancouver

Re: HOW-TO: use mod_rewrite to get rid of index.php in the url

Postby lednakashim » Thu Jan 13, 2011 10:36 am

mj wrote:
The code for making OJS URLs fully RESTful (removing index.php from both links and via mod_rewrite) is already in the current CVS branch, and will be in the next release of OJS, roughly scheduled for April.

I am a little confused, is this feature in OJS 2.3.3-3 (October 29, 2010)?
lednakashim
 
Posts: 33
Joined: Wed Dec 29, 2010 10:23 pm

Re: HOW-TO: use mod_rewrite to get rid of index.php in the url

Postby jalperin » Sat Jan 15, 2011 11:24 am

Yes. That feature has been in OJS for a while. See config.inc.php. If its not there (could be the case if you've been upgrading since before the feature was in place), you may want to look at config.TEMPLATE.inc.php and copy over the relevant section.
jalperin
 
Posts: 154
Joined: Thu Jul 06, 2006 1:03 pm
Location: Buenos Aires

Re: HOW-TO: use mod_rewrite to get rid of index.php in the url

Postby lednakashim » Sun Jan 23, 2011 5:50 pm

Thanks for the reply, I am having a bit of a problem with my setup. OJS seems to display the journal as expected, without the php, and the links do not lead to a 404 pages but features such as login or registration do not work. I am using shared hosting and my .htacess file is:
Code: Select all
RewriteEngine on
RewriteOptions Inherit
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

and my directory is
Code: Select all
website.com/ojs/

where I hope the single journal hosted is also at
Code: Select all
website.com/ojs/


Checking the error logs I see
Code: Select all
[Sun Jan 23 18:56:27 2011] [error] [client 130.126.106.43] File does not exist: /home/webhost/public_html/406.shtml, referer: http://website.com/ojs/?journal=testJournal&page=login&op=signIn
I thought 406 errors meant mime/type problems and would only occur with programs that discriminated between mime/type information (ie, web browsers don't 406 error).
Does anybody know of any steps I can take to isolate what is causing the problem?
lednakashim
 
Posts: 33
Joined: Wed Dec 29, 2010 10:23 pm

Re: HOW-TO: use mod_rewrite to get rid of index.php in the url

Postby tomp » Sun Aug 14, 2011 4:48 pm

Hello all,

I am hoping that someone might be able to above to help with a problem we're having with our breadcrumb trail. We have set up clean URLs (removed 'index.php/journaltitle/') with an htaccess rewrite and the following modification to config.inc.php (as suggested by jalperin above):

Code: Select all
    base_url[index] = http://www.domain.com
    base_url[journal] = http://www.domain.com


This mostly works well and our URLs now look like: http://www.domain.com/about. We are having one problem - the breadcrumb trail breaks in certain places. The broken links always appear at the end of a trail, usually when the trail is 3 items long.

For example, when viewing http://www.domain.com/about/editorialTeam, the final link in the trail ('Editorial Team') goes to http://www.domain.com/journaltitle/about/editorialTeam (i.e. 'journaltitle' is inserted into the URL, causing a broken link).

The other links in the breadcrumb ('Home > About the Journal') are fine. Advice on how we might fix this would be greatly appreciated!

Many thanks,
Tom
tomp
 
Posts: 5
Joined: Wed Jun 29, 2011 12:33 pm

Re: HOW-TO: use mod_rewrite to get rid of index.php in the url

Postby bradspry » Mon Feb 20, 2012 3:54 pm

My goal is the same as most, to make pretty URLs like:
http://host.domain.com/journalname

Prerequisites:
1. Apache 2 with mod_rewrite enabled
2. My OJS installation is in the DocumentRoot

For the purposes of this document, I have a journal named "Sandbox Today" located at this URL:
http://host.domain.com/sandbox

Here is my working config:

1. In OJS' config.inc.php:

Surprisingly enough, I have:
Code: Select all
restful_urls = Off


Code: Select all
base_url[index] = http://host.domain.com
base_url[sandbox] = http://host.domain.com/sandbox


The last line represents a hosted journal URL.

If you were to add another journal named "Hello World" with the path of "/helloworld", you would need to add a line like:
Code: Select all
base_url[helloworld] = http://host.domain.com/helloworld


For securing login:
Code: Select all
force_login_ssl = On



2. I went with the .htaccess method, which means you must AllowOverride All for your DocumentRoot. One consideration is if you are also running https (which I hope you are). In Apache 2, the https side of the house has it's own config file, so you must AllowOverride All for your DocumentRoot there too.

My Apache 2 config files both contain:

Code: Select all
DocumentRoot /path/to/documentroot
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>



3. Contents of my .htaccess file, which is placed in my DocumentRoot:

Code: Select all
Options FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^sandbox(.*)$ /index.php/sandbox$1 [L]

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


The first rewrite rule above is for individual hosted journals. The second rule I'll refer to as the "main" rewrite rule.

If you were to add another journal named "Hello World" with the path of "/helloworld", you would need to add a line like:
Code: Select all
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^helloworld(.*)$ /index.php/helloworld$1 [L]


If you add more journals, make sure your individual journal rewrite rules are above the "main" rewrite rule.

Hope this is helpful! It took a ton of mod_rewrite debugging to get right. I'm sure there's a better "one size fits all" regex out there, but this works just fine for today.


Sincerely,

Brad Spry
Library Webmaster
UNC Charlotte
bradspry
 
Posts: 6
Joined: Wed Aug 31, 2011 6:50 am

Re: HOW-TO: use mod_rewrite to get rid of index.php in the url

Postby asmecher » Mon Feb 20, 2012 4:21 pm

Hi all,

Brad, many thanks for posting such a detailed description. I'm sure it'll be very helpful for other users -- mod_rewrite can really be tricky.

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 8315
Joined: Wed Aug 10, 2005 12:56 pm

Re: HOW-TO: use mod_rewrite to get rid of index.php in the u

Postby bradspry » Mon Oct 29, 2012 9:28 am

This method works on OCS also, because the architecture is pretty much the same.
bradspry
 
Posts: 6
Joined: Wed Aug 31, 2011 6:50 am

Previous

Return to OJS Editorial Support and Discussion

Who is online

Users browsing this forum: Bing [Bot] and 5 guests