Apache Rewrite Rules

Open source, lightweight PHP framework for Manialink and Web development.

Moderator: NADEO

Post Reply
User avatar
gouxim
Nadeo
Nadeo
Posts: 1154
Joined: 14 Jun 2010, 17:20

Apache Rewrite Rules

Post by gouxim » 06 Mar 2012, 11:14

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
Please do not PM for support. Instead, create a thread so that everyone can contribute or benefit from the answer! 8-)

User avatar
Jojo_44
Posts: 500
Joined: 12 Jul 2010, 15:58
Location: Germany->Bavaria
Contact:

Re: Apache Rewrite Rules

Post by Jojo_44 » 06 Mar 2012, 12:10

Ahh nice ;) Big thanks :thumbsup:

regards, Jojo
Image
my english sounds very unfriendly but it isn´t ;)

User avatar
m4rcel
Posts: 653
Joined: 15 Jun 2010, 11:12
Contact:

Re: Apache Rewrite Rules

Post by m4rcel » 30 May 2012, 19:24

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 ^^
ImageImage
Image

User avatar
gouxim
Nadeo
Nadeo
Posts: 1154
Joined: 14 Jun 2010, 17:20

Re: Apache Rewrite Rules

Post by gouxim » 31 May 2012, 10:59

Thx, I've updated the post accordingly.
Please do not PM for support. Instead, create a thread so that everyone can contribute or benefit from the answer! 8-)

Post Reply

Return to “ManiaLib”

Who is online

Users browsing this forum: No registered users and 1 guest