Page 1 of 1

Apache Rewrite Rules

Posted: 06 Mar 2012, 11:14
by gouxim
Fellow coders,

I was asked about the Rewrite Rules so here's some information about it. Note: it's a fairly advanced ManiaLib topic.

First you have to activate Rewrite Rules in ManiaLib config

If you use INI config file:

Code: Select all

application.useRewriteRules = true
If you use app.php config file:

Code: Select all

$application->useRewriteRules = true;
Then you have to enable Rewrite Rules on you webserver.

Basically you need to redirect everything in the path info after index.php. Here are the rewrite rules for Apache:

Code: Select all

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/media
RewriteRule ^(.+)$ index.php/$1 [L,QSA]
Let's break it up:

Code: Select all

RewriteEngine On
=> Activates module

Code: Select all

RewriteBase /
=> Default path after domain name

Code: Select all

RewriteCond %{REQUEST_FILENAME} !-f

=> Don't redirect for existing files

Code: Select all

RewriteCond %{REQUEST_FILENAME} !-d

=> Don't redirect for existing folders

Code: Select all

RewriteCond %{REQUEST_URI} !^/media

=> Don't redirect for /media folder

Code: Select all

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

=> Redirect everything else to index.php/....


Hope it helps

Re: Apache Rewrite Rules

Posted: 06 Mar 2012, 12:10
by Jojo_44
Ahh nice ;) Big thanks :thumbsup:

regards, Jojo

Re: Apache Rewrite Rules

Posted: 30 May 2012, 19:24
by m4rcel
I want to add, that you have to remove the comments from the end of the lines to make this htaccess file actually work.

I wanted to use these rules for my own project, but the file always generated 500 errors due to these comments. Hard to find, if you only barely know how the htaccess files works ^^

Re: Apache Rewrite Rules

Posted: 31 May 2012, 10:59
by gouxim
Thx, I've updated the post accordingly.