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 responsible for making OJS work -- installing, upgrading, migrating or troubleshooting? Do you think you've found a bug? Post in this forum.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
What to do if you have a technical problem with OJS:

1. Search the forum. You can do this from the Advanced Search Page or from our Google Custom Search, which will search the entire PKP site. If you are encountering an error, we especially recommend searching the forum for said error.

2. Check the FAQ to see if your question or error has already been resolved.

3. Post a question, but please, only after trying the above two solutions. If it's a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a development question, try the OJS Development subforum.

How-to use mod_rewrite to get rid of index.php in the url

Postby kkamrani » Tue Feb 28, 2006 10:16 am

I noticed at the very end of this thread, from last year that some user wanted this:
The journal's URL will be http://ojs.ed.uiuc.edu/index.php/<path>

What I want is this:

The journal's URL will bee http://ojs.ed.uiuc.edu/<path>

What do I need to do?

I'd similarly like to have this url redirct too , because index.php is redundant in the url and makes it a hassle for individuals linking the site up and I consider it a search engine opitimization to have clean, simple urls. So, I have taken Kevin's response to use mod_rewrite in creating a .htaccessfile to mask the url and make it much cleaner, my .htaccess file looks like this:
Code: Select all
Options -Indexes
Options +FollowSymLinks
DirectoryIndex index.php index.html
RewriteEngine on
RewriteBase /
RewriteRule ^\.htaccess$ - [F]
RewriteRule ^index.php/(.*)$  e/$1

The bottom rewrite rule is the one that takes anything with a index.php and just clips it out... but when I point my browser to my url, http://primatology.info, I notice the url properly reflects my recipe, however it doesn't load up anything... meaning the redirect timed out. Is this because index.php is required to parse information?

Can anyone help out in modifying the recipe, to get it to rewrite without an index.php in the url but have it functional? I am sure there are others out there that have either tried this and ran into road blocks like, tried this and succeeded, or would like to do this in the future.
kkamrani
 
Posts: 4
Joined: Tue Feb 28, 2006 10:05 am

Postby asmecher » Tue Feb 28, 2006 10:26 am

Hi kkamrani,

Please post a working set of rules here once you get them going; I'm sure many users would find this useful.

Look into OJS's config.inc.php file for the base_url directives. These provide a way of getting OJS to generate URLs to suit your rewriting rules.

Regards,
Alec Smecher
Open Journal Systems Team
asmecher
 
Posts: 8325
Joined: Wed Aug 10, 2005 12:56 pm

Postby kkamrani » Tue Feb 28, 2006 10:51 am

asmecher wrote:Hi kkamrani,

Please post a working set of rules here once you get them going; I'm sure many users would find this useful.

Look into OJS's config.inc.php file for the base_url directives. These provide a way of getting OJS to generate URLs to suit your rewriting rules.

Regards,
Alec Smecher
Open Journal Systems Team

Hi Alec,

I have checked out config.inc.php and believe the variables you suggested for the base_url directives are something like this:
Code: Select all
base_url[index] = http://primatology.info
base_url[myJournal] = http://primatology.info/journal

I have made these changes to my base_url directive variables, and saved them, while commenting out the .htaccess edits from above to see if they do what they say they are doing. Unfortunately, I still see a index.php in the urls in my browser.

Once I get it to work, I will definately make a post about it and anounce it. I was wondering if anyone can brainstorm and troubleshoot this little challenge.

Thanks,

Kambiz
kkamrani
 
Posts: 4
Joined: Tue Feb 28, 2006 10:05 am

Postby asmecher » Tue Feb 28, 2006 12:04 pm

Hi kkamrani,

You'll need a combination of rewrite rules and OJS configuration directives. My suggestion for OJS directives is:
Code: Select all
base_url[index] = http://www.primatology.info/index
base_url[journal] = http://www.primatology.info/journal
You'll need to configure Apache to rewrite incoming requests as follows:
Code: Select all
http://www.primatology.info/index.php/more/stuff/here
maps to
Code: Select all
http://www.primatology.info/more/stuff/here
Regards,
Alec Smecher
Open Journal Systems Team
asmecher
 
Posts: 8325
Joined: Wed Aug 10, 2005 12:56 pm

Postby kkamrani » Tue Feb 28, 2006 4:34 pm

asmecher wrote:Hi kkamrani,

You'll need a combination of rewrite rules and OJS configuration directives. My suggestion for OJS directives is:
Code: Select all
base_url[index] = http://www.primatology.info/index
base_url[journal] = http://www.primatology.info/journal
You'll need to configure Apache to rewrite incoming requests as follows:
Code: Select all
http://www.primatology.info/index.php/more/stuff/here
maps to
Code: Select all
http://www.primatology.info/more/stuff/here
Regards,
Alec Smecher
Open Journal Systems Team

Thanks Alec again for the pointers this time. I have attempted to combine both the directives and Apache rewrite to no avail. I have figured my first recipe was physically rewriting index.php out of the url... instead I need to alias the urls to not include index.php. I have not figured out a way to do this.

Does anyone, who is more verbose in mod_rewrite and .htaccess recipes, know how to do this?

My question is, shouldn't the OJS directives simply work by themselves?

Kambiz
kkamrani
 
Posts: 4
Joined: Tue Feb 28, 2006 10:05 am

Postby asmecher » Tue Feb 28, 2006 4:57 pm

Hi Kambiz,

There are two things you need to accomplish here:
  • Make sure incoming requests to apache that don't contain the index.php are properly redirected to the index.php handler. This is what requires the Apache rewriting.
  • Make sure OJS is generating URLs that don't contain the index.php. This is what the config.inc.php directives accomplish.

If you get the first item working, you'll be able to point your browser to http://www.primatology.info/journal and see the appropriate information; however, any link you follow from that page will contain the index.php as usual. (This will work but it's a little ugly.)

If you get the second part working, if you point your web browser to http://www.primatology.info/index.php/journal, you'll see OJS as usual -- but all the links on the page (e.g. Login, About, etc.) won't contain the index.php part. If you haven't got rewriting in place, none of the links will work.

If you get both working, you're home free.

Regards,
Alec Smecher
Open Journal Systems Team
asmecher
 
Posts: 8325
Joined: Wed Aug 10, 2005 12:56 pm

Postby kkamrani » Tue Feb 28, 2006 11:36 pm

asmecher wrote:Hi Kambiz,

There are two things you need to accomplish here:
  • Make sure incoming requests to apache that don't contain the index.php are properly redirected to the index.php handler. This is what requires the Apache rewriting.
  • Make sure OJS is generating URLs that don't contain the index.php. This is what the config.inc.php directives accomplish.
If you get the first item working, you'll be able to point your browser to http://www.primatology.info/journal and see the appropriate information; however, any link you follow from that page will contain the index.php as usual. (This will work but it's a little ugly.)

If you get the second part working, if you point your web browser to http://www.primatology.info/index.php/journal, you'll see OJS as usual -- but all the links on the page (e.g. Login, About, etc.) won't contain the index.php part. If you haven't got rewriting in place, none of the links will work.

If you get both working, you're home free.

Regards,
Alec Smecher
Open Journal Systems Team

Ahh, I see now why I need to have both, it would be only half accomplished if I just use OJS directives. Unfortunately, I just can't seem to find the right rewrite rule for mod_rewrite to take index.php out of the loop. Thanks for the clarification, I've spent a frustrating day trying to hammer it out -- I will dabble in this later.
kkamrani
 
Posts: 4
Joined: Tue Feb 28, 2006 10:05 am

Postby asmecher » Fri Feb 09, 2007 2:09 pm

Thanks, Marcelo -- I'm sure many users will find that valuable.

Regards,
Alec Smecher
Open Journal Systems Team
---
Don't miss the First International PKP Scholarly Publishing Conference
July 11 - 13, 2007, Vancouver, BC, Canada
http://ocs.sfu.ca/pkp2007/
asmecher
 
Posts: 8325
Joined: Wed Aug 10, 2005 12:56 pm

if you want to keep OJS in a different directory but ...

Postby jalperin » Fri Feb 09, 2007 8:48 pm

... make it seem as if its not...

I had to adjust my rules a little bit when I chose to have OJS in a different folder other than my webroot, but I wanted it to appear as if it was at the webroot... So, for the record, here is what I had to do:

It may seem like a lot of extra work, just to install OJS in its own directory in the webroot...however, this was important for me because I wanted to run other applications alongside the journal, but I did not want the folders of each of them to overlap each other.

I am currently using the following configuration where:
http://www.domain.org = your domain
journal_path = what would normally appear after index.php/

config.inc.php:
Code: Select all
base_url[index] = http://www.domain.org
base_url[journal_path] = http://www.domain.org


Oh, and I had to make a small change in classes/session/SessionManager.inc.php (around line 41)
Code: Select all
ini_set('session.cookie_path', '/');  //Request::getBasePath() .


and do not have the journal redirect in the Site Settings, because this causes some redirect loop.

.htaccess:
Code: Select all
# allow access to the site admin page... (this becomes unaccessible otherwise)
RewriteRule ^admin(.*)$ /directory_with_ojs/index.php/index/admin$1 [L]


Code: Select all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/directory_with_ojs.*$
RewriteCond %{REQUEST_URI} !^$
RewriteRule ^(.*)$ directory_with_ojs/index.php/journal_path/$1 [L,QSA]


=================
on an related/unrelated note:
If people are interested, I've come up with a bit of a hack that allows completely URL rewriting (its a bit involved, so I don't want to write it all out unless there is interest).

for example, rewrite:
/article/view/public_article_id to just: /public_article_id

The basic idea is to overload the Request:url to match a certain pattern and then catch the same pattern in rewrite rules to map it back to the original.

sorry for the long post...

in a week I will launch http://www.jmir.org on OJS2 (currently not using OJS as the publishing back end). I have done a series of tricks to have the following (simple... HA!) URLs using OJS2.

http://www.jmir.org/2006/1 goes to the first issue of 2006
http://www.jmir.org/2006/1/e3 goes to the 3rd article of the first issue of 2006...

you can direct any questions regarding any of this to this forum, or contact me directly at juan [~at~] geeky [ ~dot~] net
jalperin
 
Posts: 154
Joined: Thu Jul 06, 2006 1:03 pm
Location: Buenos Aires

Apache's mod_rewrite

Postby ramon » Mon Feb 12, 2007 9:59 am

Hello all,

I for one would like to learn more about mod_rewrite.

We are planning on hosting 4 of our journals in one installation and many users would like to know how to configure their rules.

Juan, if you can send step-by-step instructions, I'd appreciate it.

I tested Rafael's solution, but the URL's get rewritten within the system.
Trying to return to OJS portal level (system index, instead of journal index) rewrites the URL and the page is not found.
Unfortunately, the server doesn't have public access for all to see.

The rewriting rules in the .htaccess file work, but the system fails to recognize the URLS.

Since I know very little of this, I'm probably doing something wrong.

.htaccess file
Code: Select all
<Directory /var/www/seer/ojs-2.1.1>
RewriteEngine On
RewriteBase /var/www/journals/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/index/$1 [L]
</Directory>


config.inc.php file
Code: Select all
base_url[index] = "http://cajueiro.ibict.br/seer/ojs-2.1.1/index"
base_url[seerdemo] = "http://cajueiro.ibict.br/seer/ojs-2.1.1/seerdemo"
base_url[support] = "http://cajueiro.ibict.br/seer/ojs-2.1.1/support"


This is the last configuration I have. I tried many different types of data in each url option, but all failed. The links to the journal get rewritten to what's in the config.inc.php, but I get "a page not found" error.
ramon
 
Posts: 926
Joined: Wed Oct 15, 2003 6:15 am
Location: Brasí­lia/DF - Brasil

Postby asmecher » Mon Feb 12, 2007 3:18 pm

Hi Ramón,

If the URLs are being generated correctly by OJS, that means the config.inc.php files have taken hold properly; however, your Apache rewrite rules are not working for some reason. I'd try simplifying your rewrite rules as much as possible and building them up piece by piece; I'm not experienced enough with rewriting to be able to suggest anything concrete, but it may be that you're providing filesystem paths (e.g. /var/www/something) instead of web server paths (e.g. /something).

Regards,
Alec Smecher
Open Journal Systems Team
---
Don't miss the First International PKP Scholarly Publishing Conference
July 11 - 13, 2007, Vancouver, BC, Canada
http://ocs.sfu.ca/pkp2007/
asmecher
 
Posts: 8325
Joined: Wed Aug 10, 2005 12:56 pm

Mod_rewrite

Postby ramon » Wed Feb 14, 2007 11:36 am

Alec,

OJS is creating the links correctly, and they are working at portal level.
However, access to journals is unavailable. The links are created correctly, but nothing happens.
ramon
 
Posts: 926
Joined: Wed Oct 15, 2003 6:15 am
Location: Brasí­lia/DF - Brasil

Postby asmecher » Wed Feb 14, 2007 11:44 am

Hi Ramón,

I think the problem is:
Code: Select all
RewriteRule ^(.*)$ index.php/index/$1 [L]
This is rewriting everything to the portal level (that /index/ part). You'll need to adjust the rules so that you can accommodate individual journals.

Regards,
Alec Smecher
Open Journal Systems Team
---
Don't miss the First International PKP Scholarly Publishing Conference
July 11 - 13, 2007, Vancouver, BC, Canada
http://ocs.sfu.ca/pkp2007/
asmecher
 
Posts: 8325
Joined: Wed Aug 10, 2005 12:56 pm

rewrite rules

Postby ramon » Fri Feb 23, 2007 5:11 am

Minholi,

Thanks, I'll test this and give you all feedback soon.
ramon
 
Posts: 926
Joined: Wed Oct 15, 2003 6:15 am
Location: Brasí­lia/DF - Brasil

Postby ozp » Sat Apr 28, 2007 9:54 pm

Hello, Ive just instaled OJS and I plan to run some journals at the same site

journals.site.com


so each one will have its own page

journals.site.com/myjournal


at my machine the path OJS is istalled is

/home/journals/public_html/



The index.php deal is something very bad for OJS, because it make it harder to remember and tell the journal URL


I tried to place a .htaccess and also to modificate the config file but nothing worked

I can config to enable journals.site.com/myjournal, but I get a 404


in the future the idea is to have lots of journals at journals.site.com and every one with its own URL journals.site.com/myjournal


what I have now is:

Code: Select all

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
ozp
 
Posts: 51
Joined: Sat Apr 28, 2007 9:01 pm

Next

Return to OJS Technical Support

Who is online

Users browsing this forum: ganesh and 6 guests