Could anyone explain the following line please?
RewriteRule ^(.*)$ /index.php/$1 [L]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The parts of the rewrite rule break down as follows:
RewriteRule
Indicates this line will be a rewrite rule, as opposed to a rewrite condition or one of the other rewrite engine directives
^(.*)$
Matches all characters
(.*)from the beggining^to the end$of the request/index.php/$1
The request will be re-written with the data matched by
(.*)in the previous example being substituted for$1.[L]
This tells mod_rewrite that if the pattern in step 2 matches, apply this rule as the “Last” rule, and don’t apply anymore.
The mod_rewrite documentation is really comprehensive, but admittedly a lot to wade through to decode such a simple example.
The net effect is that all requests will be routed through
index.php, a pattern seen in many model-view-controller implementations for PHP.index.phpcan examine the requested URL segments (and potentially whether the request was made via GET or POST) and use this information to dynamically invoke a certain script, without the location of that script having to match the directory structure implied by the request URI.For example,
/users/john/files/indexmight invoke the functionindex('john')in a file calleduser_files.phpstored in a scripts directory. Without mod_rewrite, the more traditional URL would probably use an arguably less readable query string and invoke the file directly:/user_files.php?action=index&user=john.