HOW-TO: use mod_rewrite to get rid of "?" in the url

I already read in the forum about the problems related to mod_rewrite when we register in OAI, so I used this htaccess code

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

and also modified in “config.inc.php” and “config.TEMPLATE.inc.php” to

base_url[index] = http://www.ust.edu/ojs
base_url[myJournal] = http://www.ust.edu/ojs
restful_urls = on

But the result of that it deletes just “index.php” from URL and single question character “?” is still in the URL like " http://www.ust.edu/ojs/?journal=yjmp "which cause the problem.I want the URL to be like " http://www.ust.edu/ojs/ yjmp "

Please help me
Thanks

Hi @fadia,

Try adapting the following code to your installation. Make sure to include the slashes around index.php in the rewrite rules. If you haven’t changed the document root in your apache config file, this should give you the output you’re looking for.

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

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

Hope this helps!

Chris

I modified the file that you gave me but sorry the problem was still and no Chang in the URL "

http://www.ust.edu/ojs/?journal=yjmp "

@fadia, what is your config.inc.php setting for disable_path_info?

It sounds like you want a pathinfo style URL, but you have disabled pathinfo. With pathinfo left enabled, @chrisgreencorn’s suggestion should work.

Hi all,

Note that this issue is also active on Stackoverflow.com:
http://stackoverflow.com/questions/34478962/how-to-use-mod-rewrite-to-get-rid-of-in-the-url/34538726#34538726

Regards,
Alec Smecher
Public Knowledge Project Team

thank you for reply
.
when i do "disable_path_info =off " it show me message “No input file specified” … so i made htaccess to configure Apache to
rid the question mark … but it’s not work … the URL was still appear
like “mysite/ojs/?journal=yjmp”; :tired_face:

my config.inc.php and "config.TEMPLATE.inc.php is
.
disable_path_info =on
base_url[index] = http://www.ust.edu/ojs
base_url[myJournal] = http://www.ust.edu/ojs
restful_urls = on

my htaccess …

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

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [R=301,L]
.
.
.
.
please help me :(pensive:

Hi @fadia,

I’m afraid that’s a web server configuration issue, not a problem with OJS. If you’re getting “no input file specified” you need to adjust your web server configuration. I’d suggest using Google to search for “no input file specified path_info” and you’ll find information like this:

Regards,
Alec Smecher
Public Knowledge Project Team

hi …
i have got error 404 when i do “disable_path_info =off” and I edit this file to give me more information about 404 error but i haven’t got any information :confounded:
classes/core/Dispatcher.inc.php b/classes/core/Dispatcher.inc.php
.
.
header(‘HTTP/1.0 404 Not Found’);
fatalError(‘404 Not Found’);
fatalError('404 Not Found – RequestPath: '.PKPRequest::getRequestPath());

.
.
can you help me please

Hi @fadia,

The 404 error message is coming from your web server (e.g. Apache), not OJS or PHP. To get PATH_INFO URLs working, you’ll need to fix your web server’s configuration. There’s nothing OJS can do.

Regards,
Alec Smecher
Public Knowledge Project Team

hi
i have got this error
.
.
.
ojs2 has produced an error Message: WARNING: Cannot use a scalar value as an array In file: /home/content/10/6451410/html/ojs/classes/journal/JournalSettingsDAO.inc.php At line: 83 Stacktrace: File: /home/content/10/6451410/html/ojs/classes/journal/JournalSettingsDAO.inc.php line 83 Function: PKPApplication->errorHandler(2, “Cannot use a scalar value as an array”, “/home/content/10/6451410/html/ojs/classes/journal/JournalSettingsDAO.inc.php”, 83, Array(5)) File: /home/content/10/6451410/html/ojs/pages/about/AboutHandler.inc.php line 43 Function: JournalSettingsDAO->getJournalSettings(“7”) File: (unknown) line (unknown) Function: AboutHandler->index(Array(0), Object(Request)) File: /home/content/10/6451410/html/ojs/lib/pkp/classes/core/PKPRouter.inc.php line 362 Function: call_user_func(Array(2), Array(0), Object(Request)) File: /home/content/10/6451410/html/ojs/lib/pkp/classes/core/PKPPageRouter.inc.php line 220 Function: PKPRouter->_authorizeInitializeAndCallRequest(Array(2), Object(Request), Array(0), False) File: /home/content/10/6451410/html/ojs/lib/pkp/classes/core/Dispatcher.inc.php line 134 Function: PKPPageRouter->route(Object(Request)) File: /home/content/10/6451410/html/ojs/lib/pkp/classes/core/PKPApplication.inc.php line 178 Function: Dispatcher->dispatch(Object(Request)) File: /home/content/10/6451410/html/ojs/index.php line 65 Function: PKPApplication->execute() Server info: OS: Linux PHP Version: 5.2.17 Apache Version: N/A DB Driver: mysql DB server version: 5.5.43-37.2-log
ojs2 has produced an error Message: WARNING: Cannot modify header information - headers already sent by (output started at /home/content/10/6451410/html/ojs/lib/pkp/classes/core/PKPApplication.inc.php:381) In file: /home/content/10/6451410/html/ojs/lib/pkp/classes/template/PKPTemplateManager.inc.php At line: 340 Stacktrace: File: (unknown) line (unknown) Function: PKPApplication->errorHandler(2, “Cannot modify header information - headers already sent by (output started at /home/content/10/6451410/html/ojs/lib/pkp/classes/core/PKPApplication.inc.php:381)”, “/home/content/10/6451410/html/ojs/lib/pkp/classes/template/PKPTemplateManager.inc.php”, 340, Array(7)) File: /home/content/10/6451410/html/ojs/lib/pkp/classes/template/PKPTemplateManager.inc.php line 340 Function: header(“Content-Type: text/html; charset=utf-8”) File: /home/content/10/6451410/html/ojs/pages/about/AboutHandler.inc.php line 68 Function: PKPTemplateManager->display(“about/index.tpl”) File: (unknown) line (unknown) Function: AboutHandler->index(Array(0), Object(Request)) File: /home/content/10/6451410/html/ojs/lib/pkp/classes/core/PKPRouter.inc.php line 362 Function: call_user_func(Array(2), Array(0), Object(Request)) File: /home/content/10/6451410/html/ojs/lib/pkp/classes/core/PKPPageRouter.inc.php line 220 Function: PKPRouter->_authorizeInitializeAndCallRequest(Array(2), Object(Request), Array(0), False) File: /home/content/10/6451410/html/ojs/lib/pkp/classes/core/Dispatcher.inc.php line 134 Function: PKPPageRouter->route(Object(Request)) File: /home/content/10/6451410/html/ojs/lib/pkp/classes/core/PKPApplication.inc.php line 178 Function: Dispatcher->dispatch(Object(Request)) File: /home/content/10/6451410/html/ojs/index.php line 65 Function: PKPApplication->execute() Server info: OS: Linux PHP Version: 5.2.17 Apache Version: N/A DB Driver: mysql DB server version: 5.5.43-37.2-log
ojs2 has produced an error Message: WARNING: Cannot modify header information - headers already sent by (output started at /home/content/10/6451410/html/ojs/lib/pkp/classes/core/PKPApplication.inc.php:381) In file: /home/content/10/6451410/html/ojs/lib/pkp/classes/template/PKPTemplateManager.inc.php At line: 343 Stacktrace: File: (unknown) line (unknown) Function: PKPApplication->errorHandler(2, “Cannot modify header information - headers already sent by (output started at /home/content/10/6451410/html/ojs/lib/pkp/classes/core/PKPApplication.inc.php:381)”, “/home/content/10/6451410/html/ojs/lib/pkp/classes/template/PKPTemplateManager.inc.php”, 343, Array(7)) File: /home/content/10/6451410/html/ojs/lib/pkp/classes/template/PKPTemplateManager.inc.php line 343 Function: header(“Cache-Control: public”) File: /home/content/10/6451410/html/ojs/pages/about/AboutHandler.inc.php line 68 Function: PKPTemplateManager->display(“about/index.tpl”) File: (unknown) line (unknown) Function: AboutHandler->index(Array(0), Object(Request)) File: /home/content/10/6451410/html/ojs/lib/pkp/classes/core/PKPRouter.inc.php line 362 Function: call_user_func(Array(2), Array(0), Object(Request)) File: /home/content/10/6451410/html/ojs/lib/pkp/classes/core/PKPPageRouter.inc.php line 220 Function: PKPRouter->_authorizeInitializeAndCallRequest(Array(2), Object(Request), Array(0), False) File: /home/content/10/6451410/html/ojs/lib/pkp/classes/core/Dispatcher.inc.php line 134 Function: PKPPageRouter->route(Object(Request)) File: /home/content/10/6451410/html/ojs/lib/pkp/classes/core/PKPApplication.inc.php line 178 Function: Dispatcher->dispatch(Object(Request)) File: /home/content/10/6451410/html/ojs/index.php line 65 Function: PKPApplication->execute() Server info: OS: Linux PHP Version: 5.2.17 Apache Version: N/A DB Driver: mysql DB server version: 5.5.43-37.2-log

@fadia, it looks like this new error is unrelated to this current question of your server’s PATH_INFO setup. It would be best to post it as a new topic. Posting a new topic will autosuggest existing topics, such as the following, which appears to be related:

thank you i do

  1. select * from journal_settings where setting_name like ‘metaCitations’
  2. Delete both metaCitations entries from your DB
    and this solve the error " Cannot use a scalar value as an array " thanks .
    .
    .
    i use godaddy hosting so i will try to upload ojs to another hosting and see if the problem "404 Not Found " is solve or not :confounded:

@fadia, please follow up with this new issue by replying to the topic I linked, or by posting a new topic.

hi
when i change the hosting from godaddy to webhostinghub.com and edit config.in.php to
disable_path_info =off
base_url[index] = http://online.ust.edu/ojs/index.php
base_url[ojs] = http://online.ust.edu/ojs/
restful_urls = on

and my htaccess like
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /index.php?journal=$1 [L,QSA]

the result “404 NOT found” and the url like http://online.ust.edu/ojs/JSS
.
but when i edit url and add “index.php” in url it is work and the url appear http://online.ust.edu/ojs/index.php/JSS
.
so please help me to config the htaccess to appear the index.php in url :kissing_closed_eyes:

Your RewriteRule is saying, “take anything on the URL and pass it as a parameter to ‘journal’ for the url /index.php”. A root-level index.php probably does not exist, and certainly doesn’t point to OJS.

You probably want your RewriteRule to take anything after “/ojs/” and pass it as part of the URL to “/ojs/index.php”.

If your .htaccess in in the root, your RewriteRule would look something more like:

RewriteRule ^/ojs/(.*)$ /ojs/index.php/$1 [L,QSA]

isn’t work :pensive: … RewriteRule ^/ojs/(.*)$ /ojs/index.php/$1 [L,QSA]
and my ojs in the root … when i add “index.php” manualy in url to appear like http://online.ust.edu/ojs/index.php/JSS
frist : my journal is open .
second : the error appear
ojs2 has produced an error Message: WARNING: mkdir(): Permission denied In file: /home/onlin170/public_html/ojs/lib/pkp/classes/file/FileManager.inc.php At line: 306 Stacktrace: File: (unknown) line (unknown) Function: PKPApplication->errorHandler(2, “mkdir(): Permission denied”, “/home/onlin170/public_html/ojs/lib/pkp/classes/file/FileManager.inc.php”, 306, Array(2)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/file/FileManager.inc.php line 306 Function: mkdir("/usageStats") File: /home/onlin170/public_html/ojs/lib/pkp/classes/file/FileManager.inc.php line 352 Function: FileManager->mkdir("/usageStats", Null) File: /home/onlin170/public_html/ojs/lib/pkp/classes/file/FileManager.inc.php line 351 Function: FileManager->mkdirtree("/usageStats", Null) File: /home/onlin170/public_html/ojs/plugins/generic/usageStats/UsageStatsPlugin.inc.php line 305 Function: FileManager->mkdirtree("/usageStats/usageEventLogs") File: /home/onlin170/public_html/ojs/plugins/generic/usageStats/UsageStatsPlugin.inc.php line 214 Function: UsageStatsPlugin->_writeUsageEventInLogFile(Array(16)) File: (unknown) line (unknown) Function: UsageStatsPlugin->logUsageEvent(“UsageEventPlugin::getUsageEvent”, Array(7)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/plugins/HookRegistry.inc.php line 89 Function: call_user_func(Array(2), “UsageEventPlugin::getUsageEvent”, Array(7)) File: /home/onlin170/public_html/ojs/plugins/generic/usageEvent/UsageEventPlugin.inc.php line 108 Function: HookRegistry->call(“UsageEventPlugin::getUsageEvent”, Array(7)) File: (unknown) line (unknown) Function: UsageEventPlugin->getUsageEvent(“TemplateManager::display”, Array(5)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/plugins/HookRegistry.inc.php line 89 Function: call_user_func(Array(2), “TemplateManager::display”, Array(5)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/template/PKPTemplateManager.inc.php line 332 Function: HookRegistry->call(“TemplateManager::display”, Array(5)) File: /home/onlin170/public_html/ojs/pages/index/IndexHandler.inc.php line 73 Function: PKPTemplateManager->display(“index/journal.tpl”) File: (unknown) line (unknown) Function: IndexHandler->index(Array(0), Object(Request)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/core/PKPRouter.inc.php line 362 Function: call_user_func(Array(2), Array(0), Object(Request)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/core/PKPPageRouter.inc.php line 220 Function: PKPRouter->_authorizeInitializeAndCallRequest(Array(2), Object(Request), Array(0), False) File: /home/onlin170/public_html/ojs/lib/pkp/classes/core/Dispatcher.inc.php line 134 Function: PKPPageRouter->route(Object(Request)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/core/PKPApplication.inc.php line 178 Function: Dispatcher->dispatch(Object(Request)) File: /home/onlin170/public_html/ojs/index.php line 65 Function: PKPApplication->execute() Server info: OS: Linux PHP Version: 5.5.31 Apache Version: N/A DB Driver: mysql DB server version: 5.5.43-37.2-log
ojs2 has produced an error Message: WARNING: assert(): Assertion failed In file: /home/onlin170/public_html/ojs/plugins/generic/usageStats/UsageStatsPlugin.inc.php At line: 308 Stacktrace: File: (unknown) line (unknown) Function: PKPApplication->errorHandler(2, “assert(): Assertion failed”, “/home/onlin170/public_html/ojs/plugins/generic/usageStats/UsageStatsPlugin.inc.php”, 308, Array(7)) File: /home/onlin170/public_html/ojs/plugins/generic/usageStats/UsageStatsPlugin.inc.php line 308 Function: assert(False) File: /home/onlin170/public_html/ojs/plugins/generic/usageStats/UsageStatsPlugin.inc.php line 214 Function: UsageStatsPlugin->_writeUsageEventInLogFile(Array(16)) File: (unknown) line (unknown) Function: UsageStatsPlugin->logUsageEvent(“UsageEventPlugin::getUsageEvent”, Array(7)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/plugins/HookRegistry.inc.php line 89 Function: call_user_func(Array(2), “UsageEventPlugin::getUsageEvent”, Array(7)) File: /home/onlin170/public_html/ojs/plugins/generic/usageEvent/UsageEventPlugin.inc.php line 108 Function: HookRegistry->call(“UsageEventPlugin::getUsageEvent”, Array(7)) File: (unknown) line (unknown) Function: UsageEventPlugin->getUsageEvent(“TemplateManager::display”, Array(5)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/plugins/HookRegistry.inc.php line 89 Function: call_user_func(Array(2), “TemplateManager::display”, Array(5)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/template/PKPTemplateManager.inc.php line 332 Function: HookRegistry->call(“TemplateManager::display”, Array(5)) File: /home/onlin170/public_html/ojs/pages/index/IndexHandler.inc.php line 73 Function: PKPTemplateManager->display(“index/journal.tpl”) File: (unknown) line (unknown) Function: IndexHandler->index(Array(0), Object(Request)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/core/PKPRouter.inc.php line 362 Function: call_user_func(Array(2), Array(0), Object(Request)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/core/PKPPageRouter.inc.php line 220 Function: PKPRouter->_authorizeInitializeAndCallRequest(Array(2), Object(Request), Array(0), False) File: /home/onlin170/public_html/ojs/lib/pkp/classes/core/Dispatcher.inc.php line 134 Function: PKPPageRouter->route(Object(Request)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/core/PKPApplication.inc.php line 178 Function: Dispatcher->dispatch(Object(Request)) File: /home/onlin170/public_html/ojs/index.php line 65 Function: PKPApplication->execute() Server info: OS: Linux PHP Version: 5.5.31 Apache Version: N/A DB Driver: mysql DB server version: 5.5.43-37.2-log
ojs2 has produced an error Message: WARNING: Cannot modify header information - headers already sent by (output started at /home/onlin170/public_html/ojs/lib/pkp/classes/core/PKPApplication.inc.php:381) In file: /home/onlin170/public_html/ojs/lib/pkp/classes/template/PKPTemplateManager.inc.php At line: 340 Stacktrace: File: (unknown) line (unknown) Function: PKPApplication->errorHandler(2, “Cannot modify header information - headers already sent by (output started at /home/onlin170/public_html/ojs/lib/pkp/classes/core/PKPApplication.inc.php:381)”, “/home/onlin170/public_html/ojs/lib/pkp/classes/template/PKPTemplateManager.inc.php”, 340, Array(7)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/template/PKPTemplateManager.inc.php line 340 Function: header(“Content-Type: text/html; charset=utf-8”) File: /home/onlin170/public_html/ojs/pages/index/IndexHandler.inc.php line 73 Function: PKPTemplateManager->display(“index/journal.tpl”) File: (unknown) line (unknown) Function: IndexHandler->index(Array(0), Object(Request)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/core/PKPRouter.inc.php line 362 Function: call_user_func(Array(2), Array(0), Object(Request)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/core/PKPPageRouter.inc.php line 220 Function: PKPRouter->_authorizeInitializeAndCallRequest(Array(2), Object(Request), Array(0), False) File: /home/onlin170/public_html/ojs/lib/pkp/classes/core/Dispatcher.inc.php line 134 Function: PKPPageRouter->route(Object(Request)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/core/PKPApplication.inc.php line 178 Function: Dispatcher->dispatch(Object(Request)) File: /home/onlin170/public_html/ojs/index.php line 65 Function: PKPApplication->execute() Server info: OS: Linux PHP Version: 5.5.31 Apache Version: N/A DB Driver: mysql DB server version: 5.5.43-37.2-log
ojs2 has produced an error Message: WARNING: Cannot modify header information - headers already sent by (output started at /home/onlin170/public_html/ojs/lib/pkp/classes/core/PKPApplication.inc.php:381) In file: /home/onlin170/public_html/ojs/lib/pkp/classes/template/PKPTemplateManager.inc.php At line: 343 Stacktrace: File: (unknown) line (unknown) Function: PKPApplication->errorHandler(2, “Cannot modify header information - headers already sent by (output started at /home/onlin170/public_html/ojs/lib/pkp/classes/core/PKPApplication.inc.php:381)”, “/home/onlin170/public_html/ojs/lib/pkp/classes/template/PKPTemplateManager.inc.php”, 343, Array(7)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/template/PKPTemplateManager.inc.php line 343 Function: header(“Cache-Control: no-store”) File: /home/onlin170/public_html/ojs/pages/index/IndexHandler.inc.php line 73 Function: PKPTemplateManager->display(“index/journal.tpl”) File: (unknown) line (unknown) Function: IndexHandler->index(Array(0), Object(Request)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/core/PKPRouter.inc.php line 362 Function: call_user_func(Array(2), Array(0), Object(Request)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/core/PKPPageRouter.inc.php line 220 Function: PKPRouter->_authorizeInitializeAndCallRequest(Array(2), Object(Request), Array(0), False) File: /home/onlin170/public_html/ojs/lib/pkp/classes/core/Dispatcher.inc.php line 134 Function: PKPPageRouter->route(Object(Request)) File: /home/onlin170/public_html/ojs/lib/pkp/classes/core/PKPApplication.inc.php line 178 Function: Dispatcher->dispatch(Object(Request)) File: /home/onlin170/public_html/ojs/index.php line 65 Function: PKPApplication->execute() Server info: OS: Linux PHP Version: 5.5.31 Apache Version: N/A DB Driver: mysql DB server version: 5.5.43-37.2-log
.
.
.
so i want to add index.php in url and the error be solve :kissing_closed_eyes:

Note in your error (right at the top) the message is: “Message: WARNING: mkdir(): Permission denied”.

This indicates a filesystem permission problem. In particular, your webserver is not able to write to your “files” directory to create new directories. Review the file permissions section in the wiki FAQ.

If you have additional trouble with the file permissions, branch that topic into a new post.

Feel free to continue discussing the mod_rewrite rules here, if you have more details on that.

Hi sir :slightly_smiling:
my problem is solve :slightly_smiling: but i have another error can you help me
when i enter to
http://www.ust.edu/ojs/index.php/user/register
the error is
File: /home/content/10/6451410/html/ojs/lib/pkp/classes/core/PKPPageRouter.inc.php line 184
Function: Dispatcher->handle404()

File: /home/content/10/6451410/html/ojs/lib/pkp/classes/core/Dispatcher.inc.php line 134
Function: PKPPageRouter->route(Object(Request))

File: /home/content/10/6451410/html/ojs/lib/pkp/classes/core/PKPApplication.inc.php line 178
Function: Dispatcher->dispatch(Object(Request))

File: /home/content/10/6451410/html/ojs/index.php line 65
Function: PKPApplication->execute()

and when i click (search button) or (login button ) the result page (index page ) they doesn’t open search page or login page why ?

my htaccess is

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

.
.
please can help me

Hi @fadia,

Part of the error message you quoted is missing. Can you see if you can get more of it?

Regards,
Alec Smecher
Public Knowledge Project Team

Hi
when i click the register button the error is


and this picture when i click profile button


and when i click (about button) or ( search button) or ( login button ) the result page it’s ( home page ) … doesn’t open (search page) or (about page) or (login page) like the picture


can you help me please :slightly_smiling: