7747

How to remove index.php from url slim framework setting VirtualHost?

Question:

reference image:

<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/x9KTZ.jpg" data-original="https://i.stack.imgur.com/x9KTZ.jpg" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

In this route I have the example:

C:\wamp\www\api

I work with centos in VirtualBox.

In the console of centos I can get into the same folder with this route:

cd /var/www/html/sistemaTareas/api

Well, in API folder I have:

index.php | .htaccess | Slim

Index.php:

<?php require 'Slim/Slim.php'; \Slim\Slim::registerAutoLoader(); $application = new \Slim\Slim(); $application->get('/hello/:firstname/:lastname', function ($firstname,$lastname) { echo "hola, $firstname $lastname"; }); $application->run(); ?>

.htaccess:

RewriteEngine On RewriteCond !/src/ [NC] RewriteRule ^(.*)$ src/$1 [L]

If I put this in Chrome:

http://localhost:8082/sistemaTareas/api/index.php/hello/jean/bergeret

Print this:

hola, jean bergeret

I need print this :

hola, jean bergeret

But with this URL (without index.php):

http://localhost:8082/sistemaTareas/api/hello/jean/bergeret

The VirtualHost in httpd.conf:

#<VirtualHost *:80> #ServerAdmin me@mysite.com #DocumentRoot "/var/www/html/sistemaTareas/api" #ServerName mysite.com #ServerAlias www.mysite.com #ErrorLog "logs/mysite.com-error.log" #CustomLog "logs/mysite.com-access.log" combined #<Directory "/var/www/html/sistemaTareas/api"> # AllowOverride All # Order allow,deny # Allow from all #</Directory>

For now is commented, but if I uncomment VirtualHost and I use :

http://localhost:8082/sistemaTareas/api/hello/jean/bergeret

print "not found".

I guess the virtualhost is the problem, so how can I configure it to work without index.php? (sorry my english)

Answer1:

Configure your VirtualHost like this :

<VirtualHost *:80> DocumentRoot "XXX" ServerName XXX ServerAlias XXX <Directory "XXX"> Options Indexes FollowSymLinks MultiViews AllowOverride all Require all granted </Directory> ErrorLog "XXX" </VirtualHost>

And in the base of my project i have an .htaccess file with :

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L]

Thats's all and it work for me :)

Recommend

  • How to parse to string to multidimensional array (regex?)
  • Programmatically append some td to tr - jQuery AJAX JSON
  • Conect Java client with Python server
  • function returns address of local variable in c [duplicate]
  • Convert a multidimensional array to an XML object in PHP [duplicate]
  • Slim Framework 2.0.0 Unable to use ->params() with GET
  • Object not being destroyed until end of the script if it registers spl_autoload_register();
  • How Do I Ignore Errors When Deleting Records
  • Swift 4.1 Codable/Decodable Nested Array
  • Slim Framework and Twig templating engine
  • How to render a collection of different Marionette Views
  • Twitter Bootstrap Modals not working
  • Organize routes into separate files not working properly in Slim
  • Rails Database Design: Use strings or integer?
  • Can I used mod_rewrite to change file extensions? .jpeg to .jpg for example
  • Slim Framework Method not allowed. Must be one of: POST (405)
  • .htaccess rewrite: subdomain as GET parameter and filepath afterdomain intact
  • Smart URL with optional parameters?
  • Removing the .php file extension from the URL Request
  • FlexJSON Orders Alphabetically by Default
  • LINQ to Entities does not recognize the method 'System.Collections.Generic.Dictionary`2[System.
  • Strong vs Weak entities MYSQL
  • How does this usort cmp function actually work?
  • Stop Bash Script if Hive Fails
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • Disable Enter in editText android
  • Dynamically accessing properties of knockoutjs observable array
  • Perl system calls when running as another user using sudo
  • htaccess rewriting URLs with multiple forward slashes
  • Display Images one by one with next and previous functionality
  • Upload files with Ajax and Jquery
  • SVN: Merging two branches together
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • Reading document lines to the user (python)
  • Binding checkboxes to object values in AngularJs
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?