Enable PHP short tags using .htaccess

冷暖自知 提交于 2020-01-03 17:32:06

问题


I have Apache set up on my own Centos server with several virtual web servers, and I wish to enable PHP short tags for only one of those web servers which is located at /var/www/ostickets/html. I can successfully enable short tags by adding short_open_tag=On to php.ini, however, I don't wish to globally do so, but only the one site. I've tried the following, however, nothing is displayed. I've looked at various logs, and cannot detect any errors. Is it possible that I inadvertently disabled the ability to do so and if so how do I allow it (reference "If you don't have access to the php.ini you can try to enable them trough the .htaccess file but it's possible the hosting company disabled this if you are on shared hosting:").

[root@vps html]# pwd
/var/www/ostickets/html
[root@vps html]# ls -la .hta*
-rw-r--r-- 1 root root 60 Oct  1 07:38 .htaccess
[root@vps html]# cat .htaccess
# php_flag short_open_tag on

php_value short_open_tag 1



[root@vps html]# cat test.php
<? echo('Hello World');?>
[root@vps html]#

回答1:


Have you Apache directive AllowOverride All configured for this directory ?




回答2:


Sometimes when we don't have access to modify configurations on server like in php.ini file and we still need to enable short tags for our php code. We can do it by .htaccess file. If you have not created any .htaccess file yet, create one in root directory of your website and add

php_value short_open_tag 1

That's it for .htaccess file.

Now if you want to enable that using php.ini and if you can...

just set

 short_open_tag=On

in php.ini at server and you are done..

If still it is not enabled contact your hosting support.



来源:https://stackoverflow.com/questions/19116823/enable-php-short-tags-using-htaccess

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