Enable PHP short open tags via .htaccess
When a legacy CMS or third-party script relies on <? instead of <?php, enabling the short_open_tag directive becomes a necessity. If your hosting environment runs PHP under Apache's native module rather than CGI, you might expect to configure this setting directly in an .htaccess file. Specifically, adding the line php_flag short_open_tag on should theoretically activate the feature at the directory level without touching global configuration files like php.ini.
However, many developers encounter a frustrating scenario where this directive appears ignored. The root cause often lies not in a syntax error within the .htaccess file, but in how Apache processes PHP directives and the specific permissions granted to that file by your hosting provider.
Understanding Directive Precedence
Apache distinguishes between two primary types of configuration directives: those that modify server behavior (like AddHandler or DirectoryIndex) and those that control PHP functionality (like short_open_tag). While standard Apache directives can be processed from .htaccess, PHP-specific flags are subject to strict rules regarding their location.
When PHP runs as an Apache module, it parses the configuration files in a specific order. The directive must be present when the PHP engine is initialized for that specific request context. If your host disables .htaccess overrides for PHP directives globally, adding php_flag short_open_tag on will have no effect regardless of its placement.
Verifying Apache Mode vs. CGI
The source material notes a crucial distinction: the environment must be running PHP in Apache mode (mod_php), not CGI (or FastCGI via fcgiwrap). If you are running PHP-FPM or using CGI, .htaccess files generally cannot contain PHP flags because these processes do not read .htaccess for PHP configuration; they rely on a global php.ini or a separate pool definition.
To confirm your environment supports this method, inspect your server logs. Look for errors indicating that the directive was ignored or that the file could not be processed as an Apache module. If you see messages suggesting the file is being treated differently, it is highly likely that .htaccess overrides are restricted for PHP flags on your specific hosting plan.
Alternative Configuration Paths
If php_flag short_open_tag on fails despite confirmed Apache mode, the directive might be explicitly disabled at a higher level. In some configurations, a global setting in php.ini set to Off can override local attempts to enable it, though this is less common with php_flag. More often, hosting providers disable the ability to modify PHP flags via .htaccess entirely for security and stability reasons, forcing all configuration into the main virtual host file or the global php.ini.
In such cases, the only viable solution is to contact your hosting provider. You will need to request that they enable short_open_tag globally or provide a custom php.ini override if supported. Some shared hosting environments allow this via a control panel setting (often found under "PHP Configuration" or "Select PHP Version"), bypassing .htaccess entirely.
Why Not Just Use <?php?
It is worth noting that relying on short tags is generally discouraged in modern development. The primary reason is ambiguity; a file using <? could be interpreted as XML by browsers if the MIME type isn't strictly enforced, or it could break when moving from Apache to a non-Apache environment like Nginx with PHP-FPM.
If you are maintaining an old CMS, enabling the tag via .htaccess is a quick fix that avoids code refactoring. However, if the directive fails due to hosting restrictions, consider whether the project can be migrated to use <?php. Most modern frameworks and CMS versions support short tags by default only when explicitly enabled in the main config, but the cleanest long-term solution remains standardizing on <?php blocks.
Final Recommendation
Before assuming .htaccess is broken, verify that your host allows PHP flag overrides. If you are on a shared plan, check for a PHP configuration manager in your dashboard. If the host runs Apache mode but still rejects the directive, it is almost certainly a server-level restriction rather than a local configuration issue. In those instances, a support ticket requesting global enabling of short_open_tag is the standard path forward.