do not find mvc class

Advertisement

This is my project .htaccess in mvc

 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] 

This is my simple class in the controllers folder

 class index { function __construct() { echo "this page is index"; } } 

and this is my index page and I want in the controller part in url to be index, it prints the controller part and runs the class. But these are mistakes:

 Undefined index: url 

and

 require(controllers/.php): failed to open stream: No such file or directory 

My code:

 $url = $_GET['url']; $url = rtrim($url,'/'); $url = explode('/',$url);//breaks string to array require 'controllers/'.$url[0].'.php'; $controller = new index(); print_r($url); 

The answer

Do not forget to rewrite the "base" for redirection ( RewriteBase ).
Delete the line RewriteCond %{REQUEST_FILENAME} !-l . Does a -l
Does the option even exist?

Here is an example with a document root "Publics", where the file "index.php" is located:

 Options FollowSymLinks # Uncomment if you want to only allow localhost. # Allow from 127.0.0.1 # Activate rewriting engine. RewriteEngine On # Allow pin-pointing to "index.php" using RewriteRule. RewriteBase / # Rewrite url only if no physical folder name is given in url. RewriteCond %{REQUEST_FILENAME} !-d # Rewrite url only if no physical file name is given in url. RewriteCond %{REQUEST_FILENAME} !-f # Take the common url and parse it through "index.php" as a query string, eg as "url=[...]". # ---------------------------------------------------------------------------------- # SEE: RewriteRule Flags >> https://httpd.apache.org/docs/current/rewrite/flags.html # ---------------------------------------------------------------------------------- RewriteRule ^(.+)$ index.php?url=$1 [QSA,L,B]  Options FollowSymLinks # Uncomment if you want to only allow localhost. # Allow from 127.0.0.1 # Activate rewriting engine. RewriteEngine On # Allow pin-pointing to "index.php" using RewriteRule. RewriteBase / # Rewrite url only if no physical folder name is given in url. RewriteCond %{REQUEST_FILENAME} !-d # Rewrite url only if no physical file name is given in url. RewriteCond %{REQUEST_FILENAME} !-f # Take the common url and parse it through "index.php" as a query string, eg as "url=[...]". # ---------------------------------------------------------------------------------- # SEE: RewriteRule Flags >> https://httpd.apache.org/docs/current/rewrite/flags.html # ---------------------------------------------------------------------------------- RewriteRule ^(.+)$ index.php?url=$1 [QSA,L,B] Options FollowSymLinks # Uncomment if you want to only allow localhost. # Allow from 127.0.0.1 # Activate rewriting engine. RewriteEngine On # Allow pin-pointing to "index.php" using RewriteRule. RewriteBase / # Rewrite url only if no physical folder name is given in url. RewriteCond %{REQUEST_FILENAME} !-d # Rewrite url only if no physical file name is given in url. RewriteCond %{REQUEST_FILENAME} !-f # Take the common url and parse it through "index.php" as a query string, eg as "url=[...]". # ---------------------------------------------------------------------------------- # SEE: RewriteRule Flags >> https://httpd.apache.org/docs/current/rewrite/flags.html # ---------------------------------------------------------------------------------- RewriteRule ^(.+)$ index.php?url=$1 [QSA,L,B] Options FollowSymLinks # Uncomment if you want to only allow localhost. # Allow from 127.0.0.1 # Activate rewriting engine. RewriteEngine On # Allow pin-pointing to "index.php" using RewriteRule. RewriteBase / # Rewrite url only if no physical folder name is given in url. RewriteCond %{REQUEST_FILENAME} !-d # Rewrite url only if no physical file name is given in url. RewriteCond %{REQUEST_FILENAME} !-f # Take the common url and parse it through "index.php" as a query string, eg as "url=[...]". # ---------------------------------------------------------------------------------- # SEE: RewriteRule Flags >> https://httpd.apache.org/docs/current/rewrite/flags.html # ---------------------------------------------------------------------------------- RewriteRule ^(.+)$ index.php?url=$1 [QSA,L,B] 

Related articles

JQuery is not a defined error in the asp.net mvc page

2011-06-15

I use asp.net mvc and I also use jquery ui dialog, I show a partial view in a dialog box, but Fire Fox has an error on both files when I have an Ajax.BeginForm () publication on the server. Also, destroy my dialog box in future releases! Jquery.valid

ASP.NET Core MVC Dependency Injection Issue

2017-08-11

I am relatively new in ASP.NET Core MVC and I have problems with addictive injection. I have a solution with several projects in which I want to share a context class of EF database. I have defined an interface for a configuration manager so that I c

Display in mvc table days from start date of job

2017-08-11

I'm new with MVC, I have a template with employee properties, one of the properties is public DateTime BeginJob { get; set; } public DateTime BeginJob { get; set; } public DateTime BeginJob { get; set; } public DateTime BeginJob { get; set; } public

AsP.Net MVC 5 how to call a function in view

2017-08-11

I have an application ASP.Net MVC 5 I wish to call a method from the view how can I do it? my code: My UsersList function: public ActionResult UsersList() { var User_VM = new UserVM { MyUsers = context.Users.OrderBy(u => u.Email).Include(u => u.Role

Why does Spring MVC get 404?

2017-08-11

I have a simple Spring MVC application. I get the HTTP status 404 of the report. Help me to solve this problem. Thank you. HTTP Status 404 - Not Found Status report type Message /WEB-INF/users_view.jsp Description The original server could not find a

C # MVC Recording multiple search strings for paging

2017-08-10

I saw examples here to save a string to go to the next page. But, I could not find or understand how to save multiple search parameters without requiring a variable for each search string, which I prefer not to do because I have 12 search fields. I'v