2016-04-19 29 views
1

我不是很有經驗與Apache,但我已成功地與以下設置爲我的測試箱個月運行:如何修改現有的Apache配置更改文檔根目錄爲新的應用

[email protected]:/etc/apache2/sites-enabled$ vim 000-default.conf 
<VirtualHost *:80> 
     ServerAdmin [email protected] 
     DocumentRoot /var/www/html 

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

所以基本上,無論何時我在/ var/www/html下創建一個新文件夾,它都可以在我的瀏覽器中使用。 但現在我想嘗試做如下:

  1. 我已經創建了一個新的應用程序,具有以下結構:

    在/ var/www/html等/ testrestapp/src目錄/公共/指數.PHP

它的工作原理,但我必須導航到:

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

然後應用程序返回的「sometestname」

但我想知道如何配置Apache,這樣我可以導航這樣的:

http://localhost/testrestapp/hello/sometestname 

,並得到相同的結果。

有人能指出我正確的方向嗎?不知道用什麼術語來谷歌這一點。

謝謝。

編輯1

我做了以下內容:

[email protected]:/etc/apache2/sites-enabled$ sudo a2enmod rewrite 
Enabling module rewrite. 
To activate the new configuration, you need to run: 
    service apache2 restart 

然後嘗試重新啓動:

[email protected]:/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'. 

下面是我的/啓用的網站,等/ apache2的//000- default.conf文件看起來像:

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

編輯2:

我的000-default.conf文件現在看起來是這樣的:

<VirtualHost *:80> 
     ServerAdmin [email protected] 
     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成功地重新啓動:

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

但是,當我瀏覽到http://localhost/testrestapp/hello/jojo我得到一個404錯誤。

這是我在access.log看到:

127.0.0.1 - - [19 /四月/ 2016:13:50:04 -0400]「GET/testrestapp /你好/喬喬HTTP/1.1 「404 507」 - 「」Mozilla/5.0(X11; Linux x86_64)AppleWebKit/537.36(KHTML,如Gecko)Chrome/49.0.2623.110 Safari/537.36「

+0

站長@本地只是無用 – tripleee

+0

@tripleee謝謝你讓我知道,我從當它成立之初 – Happydevdays

+0

@Happydevdays對不起,有剛剛離開一切默認你在星期一誤導你,你的編輯和時間加速是不必要的,你可以在我的答案中看到。 – menssana

回答

0

在」/ etc/apache2/sites-enabled/000默認。CONF」,使用mod_alias及以下地址:。

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