1
votes

I'm not very experienced with apache but I have managed to run with the following set up for months on my test box:

me@mydev:/etc/apache2/sites-enabled$ vim 000-default.conf 
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

So basically, anytime I create a new folder under /var/www/html, it becomes available in my browser. But now I want to try to do the following:

  1. I've created a new application, with the following structure:

    /var/www/html/testrestapp/src/public/index.php

It works but I have to navigate to:

http://localhost/testrestapp/src/public/index.php/hello/sometestname

and then the application returns "sometestname"

But I'd like to know how to configure apache so that I can navigate like this:

http://localhost/testrestapp/hello/sometestname

and get the same results.

Can someone point me in the right direction? Not sure what terminology to use to google this.

Thanks.

EDIT 1

I did the following:

me@mydev:/etc/apache2/sites-enabled$ sudo a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
  service apache2 restart

And then attempted restart:

me@mydev:/etc/apache2/sites-enabled$ service apache2 restart
Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.

Apr 19 10:14:39 mydev apache2[9010]: * The apache2 configtest failed.
Apr 19 10:14:39 mydev apache2[9010]: Output of config test was:
Apr 19 10:14:39 mydev apache2[9010]: AH00526: Syntax error on line 14 of /etc/apache2/sites-enabled/000-default.conf:
Apr 19 10:14:39 mydev apache2[9010]: RewriteBase: only valid in per-directory config files
Apr 19 10:14:39 mydev apache2[9010]: Action 'configtest' failed.
Apr 19 10:14:39 mydev apache2[9010]: The Apache error log may have more information.
Apr 19 10:14:39 mydev systemd[1]: apache2.service: Control process exited, code=exited status=1
Apr 19 10:14:39 mydev systemd[1]: Failed to start LSB: Apache2 web server.
Apr 19 10:14:39 mydev systemd[1]: apache2.service: Unit entered failed state.
Apr 19 10:14:39 mydev systemd[1]: apache2.service: Failed with result 'exit-code'.

Here's what my /etc/apache2/sites-enabled/000-default.conf file looks like:

 11         ServerAdmin webmaster@localhost
 12         DocumentRoot /var/www/html
 13         RewriteEngine  on
 14         RewriteBase    /testrestapp/
 15         RewriteRule    ^src/public/index.php/hello$  hello/  [R]

EDIT 2:

My 000-default.conf file now looks like this:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
<Directory "/var/www/html/testrestapp/">
    RewriteEngine  on
    RewriteBase    /testrestapp/
    RewriteRule    ^src/public/index.php/hello$  hello/  [R]
</Directory>

Apache restarts successfully:

me@mydev:/etc/apache2/sites-enabled$ sudo /etc/init.d/apache2 restart
[ ok ] Restarting apache2 (via systemctl): apache2.service.

But when I navigate to http://localhost/testrestapp/hello/jojo i get a 404 error.

This is what I see in the access.log:

127.0.0.1 - - [19/Apr/2016:13:50:04 -0400] "GET /testrestapp/hello/jojo HTTP/1.1" 404 507 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36"

1
webmaster@localhost is just useless. - tripleee
@tripleee thanks for letting me know. I just left everything default from when it was first set up - Happydevdays
@Happydevdays Sorry for having misleaded you yeaterday, your EDITs and time spedning were unnecessary as you can see in my answer down there. - MensSana

1 Answers

0
votes

In your "/etc/apache2/sites-enabled/000-default.conf", use mod_alias and add the following:

alias "/testrestapp/hello" "/var/www/html/testrestapp/src/public/index.php/hello"