php - Explain: Apache Rewrite, public in URL -
i realize there many hits public in url
explanation.
apache configuration:
<virtualhost *:80> servername localhost serveradmin vagrant@localhost documentroot /sites/mvc/public <directory /sites/mvc> options +followsymlinks +multiviews allowoverride require granted </directory> #loglevel info ssl:warn errorlog ${apache_log_dir}/error.log customlog ${apache_log_dir}/access.log combined </virtualhost>
public/.htaccess:
options -multiviews -indexes rewriteengine on rewritebase / rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewritecond %{request_filename} !-l rewriterule ^(.*) /index.php?url=$1 [qsa,l]
basically when try print_r()
url received, prints public first element of array. url http://127.0.0.1:8080/this/that
result in output:
array ( [0] => public [1] => [2] => )
why public included in url when not explicitly stated?
edit
p.s. wondering; reason 127.0.0.0.1:8080
resolves port 80 because being hosted via vm managed vagrant.
index.php
creates instance of app
breaks url.
app.php:
class app { // defaults. default app home/index 0 parameters protected $controller = "home"; protected $method = "index"; protected $params = []; public function __construct() { print_r($this->parseurl()); } private function parseurl() { if(isset($_get['url'])) { return $url=explode('/', filter_var(rtrim($_get['url'], '/'), filter_sanitize_url)); } } }
i had .htaccess
file in wrong directory, should have been in public/
directory rather /
root directory of application itself. junior mistake know..
i hope helps else making such simple mistake.
Comments
Post a Comment