How to set the web root and hide app.php and app_dev.php in localhost using xampp and apache?

六眼飞鱼酱① 提交于 2019-12-07 22:16:07

问题


I'm using symfony in my local computer for programming. its address is http://localhost/RTL/web/app_dev.php/secure_area.

How can I change this address to http://localhost/secure_area?

I mean removing RTL/web/app_dev.php.

I'm using xampp, apache and symfony 2.6.

other addresses could be something like these:

http://localhost/RTL/web/app_dev.php/login    =>     http://localhost/login
http://localhost/RTL/web/app_dev.php/logout   =>     http://localhost/logout
http://localhost/RTL/web/app_dev.php/admin    =>     http://localhost/admin

回答1:


Accordingly to the comments.

The RTL/web is removed adding the directive DocumentRoot "C:/xampp/htdocs/localhost/RTL/web" on your virtual host file in apache.

Then you can hide app.php using these apache mod_rewrite rules:

RewriteEngine On  
RewriteCond %{ENV:REDIRECT_STATUS} ^$  
RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
RewriteRule .? - [L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ app.php [QSA,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]    
RewriteRule .? %{ENV:BASE}app.php [L]

then restart apache server to apply the modifications.



来源:https://stackoverflow.com/questions/27460935/how-to-set-the-web-root-and-hide-app-php-and-app-dev-php-in-localhost-using-xamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!