Jump to content
xisto Community
Sign in to follow this  

Last Rule In .htaccess How is it used?

Recommended Posts

I am not particularly good when it comes to regular expressions and forming a .htaccess file, so I knew I would run into a problem sooner or later.


At the moment, I am developing a simple PHP script for a game similar to NotPr0n. As I want it to be user-friendly, I have decided to use "rewritten" URLs instead of something.php. Since the whole structure (i.e. possible URLs) is rather simple, I decided to write a set of rules manually. However, there is some overlapping, and it is causing me a lot of problems. Here is the current .htaccess file.


RewriteEngine onRewriteBase /RewriteRule ^(/)?$ inc/home.php [L]RewriteRule ^style.css$ style.css [L]RewriteRule ^izloguj-se(/)?$ inc/logout.php [L]RewriteRule ^([0-9]+)(/)?$ inc/level.php?num=$1 [L]# RewriteRule ^(.+)$ inc/file.php?name=$1

The homepage URL is riddle.mg-forum.net, and the first four rules work perfectly well:


riddle.mg-forum.net -> riddle.mg-forum.net/inc/home.php

riddle.mg-forum.net/style.css -> riddle.mg-forum.net/style.css

riddle.mg-forum.net/izloguj-se/ -> riddle.mg-forum.net/inc/logout.php

riddle.mg-forum.net/154/ -> riddle.mg-forum.net/inc/level.php?num=154 (154 can be any number)


Unfortunately, the last rule, which isn't active, isn't working properly. The idea is this: if the URL doesn't match any of the previous four, then the user must be asking for a certain file - or that is how the script should work. To achieve this, I have tried using [L] (last rule) for all the other statements as to skip the rest once the right line is found. But if I uncomment the last line, all the URLs will be rewritten to file.php?name=something! Am I using [L] improperly or is there another issue?


P.S. I wasn't quite sure whether this is the right forum, as I don't know how .htaccess and mod_rewrite are categorized. So, if any mod finds it appropriate to move the topic, feel free.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.