webdevRefinery Forum: explain this htaccess to me! - webdevRefinery Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Rate Topic: -----

User is offline gibbonweb 

  • 兄ヨハネス
  • Group: Members
  • Posts: 1615
  • Joined: 23-June 10
  • LocationMunich(DE)
  • Expertise:HTML,CSS,PHP,Javascript,Python,SQL,Graphics

Posted 04 February 2012 - 10:01 AM (#1)

explain this htaccess to me!


kthxbye!
Hi guys, so I went with cherokee as my webserver and it's pretty neat so far. Only that every time I install software which uses friendly urls, they only talk about htaccess which isn't used on cherokee.
In order to translate htaccess rules to the cherokee configuration, I obviously need to understand them... and that's the issue - I'm an idiot when it comes to anything apache2. The only thing I can do on my own in htaccess is say Options -Indexes and define a htusers file... :huh:


So, could someone please EXPLAIN to me line by line what the following htaccess does:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.+$ index.php [L]
</IfModule>



thank you!
caution: may contain irony.
NOTE that quality posts can only be guaranteed if a +rep advance payment has been made.
gibbonweb | github | hdr photography

Posted Image
0


User is offline ThatRailsGuy 

  • José the Jalapeño ... on a Stick
  • Group: Members
  • Posts: 4387
  • Joined: 02-October 10
  • Expertise:HTML,CSS,PHP,Java,Javascript,Ruby on Rails,SQL

Posted 04 February 2012 - 10:11 AM (#2)

Post below this one.
Posted Image Reliable Rabbit
Reliable Rabbit, my "company."
0


User is online Cyril 

  • Get off my canvas!
  • Group: Members
  • Posts: 2312
  • Joined: 03-August 10
  • LocationParis, France
  • Expertise:HTML,CSS,PHP,Javascript,Node.js,Graphics

Posted 04 February 2012 - 10:31 AM (#3)

It checks if the requested URL isn't a file or folder, and if it isn't, it rewrites the URL onto index.php ;)

html, css, php, python, graphics
centideo :: cntdin :: github :: twitter :: dribbble :: forrst
0


User is offline Ruku 

  • Damn, grapes are delicious.
  • Group: Members
  • Posts: 1177
  • Joined: 17-April 10
  • LocationIn a TCP/IP packet.
  • Expertise:HTML,CSS,PHP,Javascript,Python,SQL

Posted 04 February 2012 - 12:30 PM (#4)

<IfModule mod_rewrite.c>

If mod_rewrite is loaded...

    RewriteEngine On

Enable it for any files under this directory.

    RewriteBase /

Explicitly tell it to act relative to the web root; a fix needed for the ignorant masses who place trust in mod_security and probably others (it's a chocolate teapot).

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

Trigger it if no file (
-f
) or directory (
-d
) with the filename the request is for exists.
REQUEST_FILENAME
is parsed such that the GET parameter query string and FastCGI path info stuff is stripped.

    RewriteRule ^.+$ index.php [L]

Process the request by continuing as if the
REQUEST_FILENAME
were index.php. The
L
flag aborts any further processing of rewrite rules, forcing this match to take precedence.

</IfModule>

Duh :P

I did write up a quick post that had the most common Apache rewrite ruleset converted for nginx. I can go dig it out if you need it for anything?
Luke Carrier.
Need hosting? I have servers!
3


User is offline gibbonweb 

  • 兄ヨハネス
  • Group: Members
  • Posts: 1615
  • Joined: 23-June 10
  • LocationMunich(DE)
  • Expertise:HTML,CSS,PHP,Javascript,Python,SQL,Graphics

Posted 04 February 2012 - 02:17 PM (#5)

Ruku, thanks a bunch! +1 for the chocolate teapot, sounds yummy (I don't get the refernce, but that's fine ;))

I was able to convert that into a cherokee rule pretty easily - once my blog is up I'll post the resulting rule since it might be of interest for anyone with a similar setup.
caution: may contain irony.
NOTE that quality posts can only be guaranteed if a +rep advance payment has been made.
gibbonweb | github | hdr photography

Posted Image
0


User is offline Ruku 

  • Damn, grapes are delicious.
  • Group: Members
  • Posts: 1177
  • Joined: 17-April 10
  • LocationIn a TCP/IP packet.
  • Expertise:HTML,CSS,PHP,Javascript,Python,SQL

Posted 04 February 2012 - 02:48 PM (#6)

View Postgibbonweb, on 04 February 2012 - 02:17 PM, said:

Ruku, thanks a bunch! +1 for the chocolate teapot, sounds yummy (I don't get the refernce, but that's fine ;))

I was able to convert that into a cherokee rule pretty easily - once my blog is up I'll post the resulting rule since it might be of interest for anyone with a similar setup.


Glad I could be of assistance :)

The chocolate teapot thing is just logic - if you tried to make tea in it, it'd melt. mod_security is equally useless in most situations, except for where the rules have been thought out and you're accommodating only certain apps (the cooler variety? heh).
Luke Carrier.
Need hosting? I have servers!
0


User is offline Daniel15 

  • dan.cx
  • Group: Moderators
  • Posts: 3038
  • Joined: 17-April 10
  • LocationMelbourne, Australia
  • Expertise:HTML,CSS,PHP,Java,Javascript,SQL

Posted 04 February 2012 - 06:09 PM (#7)

As for Cherokee, there's several different ways to get a similar configuration. Here's one that I use, rules in this order:

1. PHP rule (added by Cherokee's wizard)
2. "File exists" rule, handler of "List and Send", "Match any file" ticked, set to "Final"
3. Change default rule to "Redirection" handler, with this rule:
- Type: Internal
- Regular expression: ^(.+)$
- Substitution: /index.php/$1

This is the set of rules that most closely matches that Apache configuration.
Daniel15! :D
Repeat after me: jQuery is not JavaScript. It is not the answer to every JavaScript-related question. When you have to write some JavaScript, do not instantly react with "Oh, I'll do that with jQuery!"

javascript:alert((''+[][[]])[!+[]+!+[]]+(![]+[])[+!+[]]+(''+!+[]/[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(''+!![])[+!+[]+!![]+!![]]+(![]+[])[!+[]+!+[]]+(+!+[])+(!+[]+!+[]+!+[]+!+[]+!+[]))

View PostKyek, on 16 November 2011 - 11:14 AM, said:

Daniel15 is ruining my life D:

View Postmorrison_levi, on 30 September 2011 - 04:10 PM, said:

They added more features to tables because. . . oh, yeah, they do have valid uses! Ever heard of data? We do still use that. :)
1


User is offline gibbonweb 

  • 兄ヨハネス
  • Group: Members
  • Posts: 1615
  • Joined: 23-June 10
  • LocationMunich(DE)
  • Expertise:HTML,CSS,PHP,Javascript,Python,SQL,Graphics

Posted 05 February 2012 - 04:05 AM (#8)

View PostDaniel15, on 04 February 2012 - 06:09 PM, said:

As for Cherokee, there's several different ways to get a similar configuration. Here's one that I use, rules in this order:

1. PHP rule (added by Cherokee's wizard)
2. "File exists" rule, handler of "List and Send", "Match any file" ticked, set to "Final"
3. Change default rule to "Redirection" handler, with this rule:
- Type: Internal
- Regular expression: ^(.+)$
- Substitution: /index.php/$1

This is the set of rules that most closely matches that Apache configuration.

Lol, I've done the inverse of your 2. and 3.:


1. PHP rule (added by Cherokee's wizard) (non final)
2. NOT "File exists" rule, "Redirection" handler (final)
3. default rule w/ "List & Send" handler.


...and I have yet to meet someone who can define what "final" vs. "non final" means... ;)
caution: may contain irony.
NOTE that quality posts can only be guaranteed if a +rep advance payment has been made.
gibbonweb | github | hdr photography

Posted Image
1


User is offline Daniel15 

  • dan.cx
  • Group: Moderators
  • Posts: 3038
  • Joined: 17-April 10
  • LocationMelbourne, Australia
  • Expertise:HTML,CSS,PHP,Java,Javascript,SQL

Posted 05 February 2012 - 04:51 PM (#9)

Quote

Lol, I've done the inverse of your 2. and 3.:

Haha, that works too.

Quote

...and I have yet to meet someone who can define what "final" vs. "non final" means...

Final is the equivalent of the [L] flag in mod_rewrite rules. It means that once that rule is matched, no other rules will be applied to the request. With the rules I posted, if the second rule (File Exists) matches, you don't want to do the redirect, so it needs to be set to final.

The PHP rule only tells Cherokee how to handle files with "php" as the extension. It doesn't do anything else itself, which is why it's non-final. You can still apply redirects to .php requests, for example.
Daniel15! :D
Repeat after me: jQuery is not JavaScript. It is not the answer to every JavaScript-related question. When you have to write some JavaScript, do not instantly react with "Oh, I'll do that with jQuery!"

javascript:alert((''+[][[]])[!+[]+!+[]]+(![]+[])[+!+[]]+(''+!+[]/[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(''+!![])[+!+[]+!![]+!![]]+(![]+[])[!+[]+!+[]]+(+!+[])+(!+[]+!+[]+!+[]+!+[]+!+[]))

View PostKyek, on 16 November 2011 - 11:14 AM, said:

Daniel15 is ruining my life D:

View Postmorrison_levi, on 30 September 2011 - 04:10 PM, said:

They added more features to tables because. . . oh, yeah, they do have valid uses! Ever heard of data? We do still use that. :)
1


User is offline gibbonweb 

  • 兄ヨハネス
  • Group: Members
  • Posts: 1615
  • Joined: 23-June 10
  • LocationMunich(DE)
  • Expertise:HTML,CSS,PHP,Javascript,Python,SQL,Graphics

Posted 06 February 2012 - 12:58 AM (#10)

View PostDaniel15, on 05 February 2012 - 04:51 PM, said:

Haha, that works too.


Final is the equivalent of the [L] flag in mod_rewrite rules. It means that once that rule is matched, no other rules will be applied to the request. With the rules I posted, if the second rule (File Exists) matches, you don't want to do the redirect, so it needs to be set to final.

The PHP rule only tells Cherokee how to handle files with "php" as the extension. It doesn't do anything else itself, which is why it's non-final. You can still apply redirects to .php requests, for example.

Ha! Awesome. Thanks - that's not even in the docs like that (at least, I looked for this explanation and never found it ;) )
caution: may contain irony.
NOTE that quality posts can only be guaranteed if a +rep advance payment has been made.
gibbonweb | github | hdr photography

Posted Image
0


User is offline Daniel15 

  • dan.cx
  • Group: Moderators
  • Posts: 3038
  • Joined: 17-April 10
  • LocationMelbourne, Australia
  • Expertise:HTML,CSS,PHP,Java,Javascript,SQL

Posted 06 February 2012 - 01:23 AM (#11)

You must be looking in the wrong place :P

From http://www.cherokee-...al_servers.html

Quote

Final: If this flag is present it means that no other rules will be applied after this one, even if the request also matches other rules with lower priority. The server will issue a response with whatever behavior it has figured out by then.

Daniel15! :D
Repeat after me: jQuery is not JavaScript. It is not the answer to every JavaScript-related question. When you have to write some JavaScript, do not instantly react with "Oh, I'll do that with jQuery!"

javascript:alert((''+[][[]])[!+[]+!+[]]+(![]+[])[+!+[]]+(''+!+[]/[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(''+!![])[+!+[]+!![]+!![]]+(![]+[])[!+[]+!+[]]+(+!+[])+(!+[]+!+[]+!+[]+!+[]+!+[]))

View PostKyek, on 16 November 2011 - 11:14 AM, said:

Daniel15 is ruining my life D:

View Postmorrison_levi, on 30 September 2011 - 04:10 PM, said:

They added more features to tables because. . . oh, yeah, they do have valid uses! Ever heard of data? We do still use that. :)
1


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Enter your sign in name and password


Sign in options
  Or sign in with these services