syntax for setting output_buffering in .htaccess? (php 5) - .htaccess

What is the syntax for setting output_buffering to off in .htaccess?
Provide a complete .htaccess file content please?

This is isn't really a hard thing to find. Anyway, you need to make sure you have PHP running as an apache module for this to work in .htaccess.
http://php.net/manual/en/configuration.changes.php
<IfModule mod_php5.c>
php_value output_buffering Off
</IfModule>

Related

How to enable mod_rewrite via .htaccess?

I'm going to enable mod_rewrite (modsecurity ) in Cpanel and here is my htaccess, please advice me how to enable it.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|public|assets|uploads|themes|install|updates|asset|mob|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
<FilesMatch "\.(jpg|jpeg|png|gif|swf|css)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
Thanks in advance
As per your provided .HTACCESS code, mod_rewrite is already enabled..
RewriteEngine on
While Mod_security can not be enabled/disabled from cPanel end. If you have access to server OR WHM panel then you can do it and make sure you have compiled APACHE to enabl mod_security, otherwise contact your hosting provider to do it for you.
You can find APACHE compile for mod_security details from here...
mod_rewrite is not the same thing as mod_security. The first allows you to create custom rewrite rules in an .htaccess file like the ones you have mentioned. Mod_security is a security module for apache (protects your website against php sql injection attacks, xss etc).
mod_rewrite is enabled by default on a fresh cPanel/WHM install.
What is exactly not working on your actual config/setup?

.htaccess rule for conditional php short_tags

I am allowing php short tags in the .htaccess file by using:
php_flag short_open_tag on
I would like to make this conditional, ie, when the param st0 is in the URL then short_tag off else short_tag on
What is the .htaccess rule to achieve this?
First of all you need to understand that this is not entirely possible in .htaccess as php_flag directive is unconditional.
Here is work around solution to make it work:
Step 1: In your root .htaccess have this code:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)st0= [NC]
RewriteRule !^_st0\.php/ _st0.php%{REQUEST_URI} [L]
<Files _st0.php>
php_flag short_open_tag on
</Files>
Step 2: Create a file called _st0.php in DocumentRoot:
<?php include substr($_SERVER["PATH_INFO"], 1); ?>
Here is how it works:
mod_rewrite will rewrite every request with st0 parameter to /_st0.php.
<Files _st0.php> directive will conditionally turn on short_open_tag ONLY for file /_st0.php.
/_st0.php will just forward the request to your actual request URI thus enabling short_open_tag for your case of URL with parameter st0 only.

.htaccess php_value auto_prepend_file makes 500 error. How can I fix this?

My .htaccess is as follows:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /school
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?page=$1
RewriteRule ^([a-zA-Z0-9]+)$ index.php?page=$1
php_value auto_prepend_file ./inc/library.php
ErrorDocument 404 /school/index.php?page=404
As of the ./, I read that indicates a relative path.
Note: This information was taken nearly verbatim from another website, I thought it explained the issue well and I highly suspect this is the problem:
Using php_flag or php_value in .htaccess files
Some PHP scripts suggest using "php_value" or "php_flag" commands in .htaccess files, as in this example:
php_value include_path ".:/usr/local/lib/php"
php_flag display_errors Off
php_value upload_max_filesize 2M
php_value auto_prepend_file "./inc/library.php"
However, some servers run PHP in "CGI mode" (not as an Apache module), so you can't use "php_value" or "php_flag" commands in .htaccess files. If you try to do so, you'll see an "internal server error" message.
You can modify your php.ini file to get the same effect, though. In fact, modifying php.ini is actually more flexible than using php_value or php_flag: there are many things you can't override using .htaccess files, but you can override almost any PHP setting in the php.ini file.
To get the same effect as the .htaccess lines above, you would simply add these lines to your custom php.ini file:
include_path = ".:/usr/local/lib/php"
display_errors = Off
upload_max_filesize = 2M
auto_prepend_file = "./inc/library.php"
Note: Some systems will require quotes around the paths, and some must not use quotes.
You could use htscanner PHP module if you want to use php_value in your .htaccess files when running php as a CGI/FastCGI application.

Apache mod_rewrite not working

I have a problem with the mod_rewrite module for Apache 2.2
My code will neither work on localhost (Wamp on Win8 Pro, IPv6) nor on the webhotel (site5.com).
My goal is to generate SEO friendly URLs as:
www.xy.com/featured-artists.html
instead of:
www.xy.com/index.php?pageID=Artists
The PHP variable $pageID is defined on line 1 in my index.php:
<?php isset($_GET['pageID']) ? $pageID = $_GET['pageID'] : $pageID = 'Forside';?>
The code for the rewrite in my .htaccess file looks as follows:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^([^/.]+)/?$ /index.php?page=$1
</IfModule>
Unfortunately that doesn't have any effect on the site. The .htaccess file is working properly though, since other sections like
ErrorDocument 404 /index.php?pageID=404
work as expected.
No matter what I do - it won't work. So I really hope that some of you can help me with that.
Thanks!
Mod_rewrite doesn't seem to be turned on. Your rules are inclosed in a IfModule container:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^([^/.]+)/?$ /index.php?page=$1
</IfModule>
So the rules aren't going to get executed. You need to turn on mod rewrite in server config (or your webhost) if you want any of your rules to work. Otherwise, it doesn't matter what you try.
Once you had mod_rewrite loaded, your rules should do close to what you want. It'll take /something and internally rewrite it to /index.php?page=somethin.

.htaccess mod-rewrite -- Not Redirecting

Okay, so I have a script that works like adf.ly; you submit a URL, the Url is shortened and then an interstitial advertisement shown before you're taken to your URL. I have the following .htaccess located in the root:
DirectoryIndex index.php
FileETag none
ServerSignature Off
Options All -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([0-9a-zA-Z]{1,6})$ fly/?to=$1 [L]
RewriteRule ^([0-9]{1,9})/banner/(.*)$ fly/?uid=$1&adt=2&url=$2 [L]
RewriteRule ^([0-9]{1,9})/(.*)$ fly/?uid=$1&adt=1&url=$2 [L]
</IfModule>
The script is generating the shortURL's (you can try here: http://www.twitsym.com/short/) however it is not redirecting to fly.php and then the final URL. I'm terrible with .htaccess and have little to no knowledge. Can anybody edge me further as to what might be causing the problem?
Directory structure is:
.../
.../fly/index.php
Thank you again, StackOverflow!
it seems that you will need the LogLevel directive somewhere in your httpd.conf or vhost.conf if this is a virtual server. See this post for a similar question.
The code would be:
RewriteLogLevel 3
RewriteLog "/usr/local/var/apache/logs/rewrite.log"
Where is the htaccess supposed to be redirecting to (i.e. which URL should lead whereto?)
Additionally, you asked for being redirected to fly.php, however it does not occur in your .htaccess. Was this your intention?

Resources