Single journal url .htaccess configuration

I’m currently following this thread (Please, How To Direct Single Journal To Web Root (http://journalpage.com) instead of (http://journalpage.com?index.php/ojs) - #2 by ctgraham) for removing index.php and journal name in the url.

In particular:
I would like this:
www.aghamx.com/index.php/aghamx
to become:
www.aghamx.com

I have already tried copying different mod rewrite conditions and I have also already set the following in the config file:
base_url[‘index’] = aghamx.com
base_url[‘aghamx’] = http://www.aghamx.com
restful_urls = On

But unfortunately, it ends up with redirect loops or incorrect display.

1 Like

If you just have a single journal within your installation, it is far easier to just set the “Journal Redirect” in the Site Configuration than to create a custom mod_rewrite solution. This would allow a user who enters www.aghamx.com to be gracefully redirected to www.aghamx.com/index.php/aghamx. (Or with minimal mod_rewrite configuration, to www.aghamx.com/aghamx.)

If you are committed to “inverting” the site and journal structure (as described in the other post), please share your mod_rewrite configuration here, and we can try to offer some suggestions.

Hi @ctgraham. Thank for the quick reply. However, I can’t seem to find where the Journal Redirect settings are. Is it found in the admin dashboard?

In 2.4.x:
User Home → Site Administrator → Site Settings → Journal redirect

In 3.x:
Admin → Administration → Site Settings → Journal redirect

1 Like

Hi @ctgraham. I would really appreciate step-by-step help with a correct htaccess configuration especially now that the website is already public.

My config file base url settings:
base_url[‘index’] = http://www.aghamx.com/
base_url[‘aghamx’] = http://www.aghamx.com/
restful_urls = On

My htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^aghamx.aghamx.com$
RewriteRule ^$ http://aghamx.aghamx.com/index [L,R=301]

RewriteEngine on RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^/index/(.*)$ /index.php/index/$1 [L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/aghamx/$1 [L]

Unfortunately, this results in incorrect page display and a lot of redirects (?) I guess.

I also tried just removing index.php using the following config.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

Still does not work.

May I request your help with this. Also, it would be really helpful to be able to easily achieve this in the future since single journals in root urls should be common. Thanks a lot.

The best solution for single journals in root URLs is the “Journal redirect” within site settings. This provides a “one click” setting to make the site homepage redirect to the journal homepage, with no fancy intervention with the base_urls and mod_rewrite rules.

Regarding your current config, your .htaccess file seems to reference a subdomain of “aghmx.aghamx.com”, but this isn’t referenced anywhere in your config.inc.php base_urls. Is this intentional? Your rewrites will substantially depend on whether you want the side index on the same domain (or subdomain) as the journal, or on a different domain (or subdomain).

Hello @ctgraham

I’ve tried looking for the Journal Redirect settings but can’t really find it in the site administration page. The account role is journal manager.

Btw, as of now, redirecting to the aghamx journal is not an issue (if I’m not mistaken). Entering www.aghamx.com automatically redirects to aghamx.com/index.php/aghamx.

What I really wanted to do is more like cleaning the URL by eliminating index.php/aghamx so that all subdirectories would just appear as www.aghamx.com/* instead of www.aghamx.com/index.php/aghamx/*

I’m finding it hard to understand how mod rewrite works and I just followed a thread from the forum with the same problems. I’ve read these threads

You said here that

There is no mechanism in the software to create vanity URLs which automatically strip the RESTful context from pages, but you can create the URL rewrites by adding additional mod_rewrite rules, and then when adding links in the menu or in HTML you would need to manually reference those links. The pages would still be available at their original URI, and could be indexed as such if these links are crawled. I think this would get you 90% of the way there, though I think it would be a lot of effort for minimal benefit.

I now changed the lines into:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.aghamx.com$
RewriteRule ^$ http://www.aghamx.com/index [L,R=301]
did not work still. too many redirects

Would you suggest that I persist on having a vanity URL? Or just leave it as it is? But people would really prefer www.aghamx.com/ over www.aghamx.com/index.php/aghamx

It looks like you do not have full administrator privileges on your install. Do you have access to the admin account? There should be a Site Settings option if you have administrator privileges.

I would recommend a install of OJS is the document root of www.aghamx.com, with a simple mod_rewrite to strip off the index.php, enabling restful_urls. Use the Journal Redirect to go to your journal automatically.

This would require no custom base_url overrides. It would give your journal a base url of http://www.aghamx.com/aghamx. Any access to http://www.aghamx.com would automatically redirect to http://www.aghamx.com/aghamx. Your site management would be accessible at http://www.aghamx.com/index.

The mod_rewrite rule would be as simple as:

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

(But note that this rule will still depend on your specific server configuration!)

If you really only ever intend to host the one journal, you might be able to improve the URL by using a journal shortname of “journal” or “pubs” or similar, for a journal URL of http://www.aghamx.com/pubs/, so “aghamx” does not repeat in the URL.

If you need to get the journal’s root down to the domain route, this is possible, but it really does require special expertise with mod_rewrite and is extremely situation dependent.

Hi @ctgraham

I thought I was using the admin account because it was the account I entered during the first installation. I don’t know how I don’t seem to have admin privileges. In order to make sure I had not made an error somewhere during the installation, I did a fresh installation in localhost, entered a new account, then immediately tried to navigate to the site settings but also found none. I navigated to the role settings and it is indicated that the account Im using (which I created during installation and should be the site admin), is journal manager. I think this is exactly the same case happening in the live website. What do you think might be wrong? How could I get those admin privileges? Hopefully without doing a fresh installation in the web server…

Btw, I tried the mod rewrite rule you suggested but still without success. Maybe it would work once the journal redirect settings are corrected.

Also, I think that’s a really good solution, I will be setting the journal URL to www.aghamx.com/journal so the remaining concern would only removing index.php.

Thank you for the support! Hopefully this gets fully resolved soon! :slight_smile:

What specific version of OJS are you using (including the last “dot release”)? When you tried a clean install on localhost, did you have the installer create a new database, or did you already have a database?

I’m using 3.0.1. Oh yes, about that, I could not create a new database and the installation could not proceed. I just did the installation in localhost yet again to make sure. And now I remember that I’ve been getting “A database error has occurred: Access denied for user…”
Only way I could resolve it was create a new database in phpmyadmin in hostgator cpanel and then created a new user and elevated its privileges to that database. And then I entered the database and the user to the OJS Installation and OJS installation was successful… hmmm… Could this be the reason?

I would be primarily concerned about installing “over top” of an existing database. If you have a blank database created in phpmyadmin which the OJS install populates, or if you have the installer create the database, I would expect the user your specify in the installation form to get full admin privileges.

I replicated the problem of the Site Settings not displaying in 3.0.1 and 3.0.2. I was able (in 3.0.2) to manually enter the URL of “index.php/index/admin/settings” and to pull up and to save the Site Settings as the administrator. Manual access to index.php/index/admin/settings is inconclusive. I’ve found the Site Settings will only show if more than one journal is defined. I’m going to gather a bit more information and then file a bug report.

Do you have an Apache DirectoryIndex directive which applies a priority to anything over index.php? I had:
DirectoryIndex index.html index.php
and this caused PHP’s PATH_INFO to be malformed under mod_rewrite.

Changing this to DirectoryIndex index.php allowed OJS to behave as expected, with the Site index automatically redirecting to the Journal index for a single journal install.

Hi @ctgraham :slight_smile:

As per your suggestion, I put a DirectoryIndex line in my htaccess config

DirectoryIndex index.php

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !^.*/index.php/.*$ RewriteRule ^/aghamx/(.*)$ /aghamx/index.php/$1 [QSA,L]

Going to aghamx.com would then redirect to http://www.aghamx.com/journal but returns a 404 error. Going to http://www.aghamx.com/index.php/journal would load the homepage but displays incorrectly. Also, I could still not find the Site Settings in the admin dashboard.

These lines won’t work for you:

RewriteCond %{REQUEST_URI} !^./index.php/.$
RewriteRule ^/aghamx/(.*)$ /aghamx/index.php/$1 [QSA,L]

They say: the next RewriteRule applies only to requests which don’t start with any character, followed immediately by the literal “/index.php/”, and ending exactly in one character. Then, for any request that matches that and starts exactly with “/aghamx/” followed by any captured characters, redirect the request to index.php under the aghamx folder, with the captured characters apended.

The two regular expressions are contradictory.

Try directives of:

  RewriteCond %{REQUEST_URI} !^.*/index.php/.*$
  RewriteRule ^/(.*)$ /index.php/$1 [QSA,L]

Hi @ctgraham

Sorry I’ve been busy the past days. I implemented those lines but I don’t observe any effect in the URL.

What specifically do you mean by “don’t observer any effect in the URL”?

Do you still have restful_urls on in your config.inc.php?

I have the same issue, I can not see the SITE SETTING in

Admin → Administration → Site Settings → Journal redirect

In my case there is no other users, and the only user is the one who installed the OJS 3.0.2.0.

When I try to access , It get

…/index.php/index/user/authorizationDenied?message=user.authorization.accessDenied

I don’t find it either as the journal admin

@kawahyu, do you have a site with multiple journals, or with a single journal? This option will only appear if your site has multiple journals.

@Dilan_Rostam, I wonder if this thread might be relevant to your error message:

1 Like