htaccess php_value auto_prepend_file gives me internal 500 error - .htaccess

I have a problem with php_value auto_prepend_file from htaccess. It gives me 500 Internal Server Error. The following htaccess codes is working fine on localhost but gives me 500 Internal Server Error on online server. Where is the problem and what is the solution ? Anyone can help me in this regard please ?
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /script/
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ %1 [R=302,NE,L]
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index\.php$ $1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^post/([\w-]+)/?$ sources/post.php?msgID=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteRule ^(.+?)/?$ index.php?pages=$1 [L,QSA]
php_value auto_prepend_file "/home/*****/public_html/script/path.php"

For the php_value directive to work it needs to be an environment where PHP is loaded as a module into the Apache webserver.
This is not necessarily the case. Your online server could for example forward PHP requests to a FPM-worker via FCGI, without mod_php enabled in Apache.
You may place a file with just a phpinfo() in it on the server to check if that is the case. For me, it then displays Server API FPM/FastCGI in the 3rd row.
In this case, overwriting php.ini settings via .htaccess is not possible. Your only options would be to change the FPM/Pool config (given you have access to that) or try ini_set.
Edit: It may also be possible to utilize .user.ini files as an alternative: https://medium.com/#jacksonpauls/moving-from-mod-php-to-php-fpm-914125a7f336 / https://secure.php.net/manual/en/configuration.file.per-user.php - thanks #anubhava

Related

AH10039: FastCGI: server and Request exceeded the limit of 10 internal redirects due to probable configuration error. Multi SSL

My shop is supposed to work on monday ... and it is not ready (yet). Stress ...
Recently I moved to SSL and remove the now useless domain mapping plugin.
I am experiencing various problems ( a) download of downloadable files on my WooCommerce shop often fail , b) the theme displayed on my main site homepage is not the one activated ...)
Debug mode is on but no error appears in my pages.
My logs are full of errors :
AH10039: FastCGI: server
and
server and Request exceeded the limit of 10 internal redirects due to probable configuration error.
I suspect my htaccess to be causing at least the 2nd error. ( And I am pretty ignorant in that matter ...) Here it is :
#WFIPBLOCKS - Do not remove this line. Disable Web Caching in Wordfence to remove this data.
Order Deny,Allow
#Do not remove this line. Disable Web Caching in Wordfence to remove this data - WFIPBLOCKS
#SetEnv PHP_VER 5
#SetEnv REGISTER_GLOBALS 0
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress
# ultimate hotlink protection
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g?|png)$ [NC]
RewriteCond %{HTTP_REFERER} !^https?://([^.]+\.)?mainDomain\. [NC]
RewriteCond %{HTTP_REFERER} !^https?://([^.]+\.)?subDomain1\. [NC]
RewriteCond %{HTTP_REFERER} !^https?://([^.]+\.)?subDomain2\. [NC]
RewriteCond %{HTTP_REFERER} !^https?://([^.]+\.)?subDomain3\. [NC]
RewriteCond %{HTTP_REFERER} !^https?://([^.]+\.)?subDomain4\. [NC]
RewriteRule \.(gif|jpe?g?|png)$ - [F,NC,L]
</ifModule>
<FilesMatch "\.(ttf|otf|woff)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
Thanks for any advice !
Nicolas
Solved !
I simply went back to the standard .htaccess given in the network settings

.htaccess url rewrite GET parameter and remove .php without breaking javascript/css

Sorry if I explain my problem badly, It's a little hard to explain what's going wrong*
I've been playing around with the .htaccess file for a while now, Trying to get this to work.
I have the following files in my website directory:
- index.php
- generator.php
- menu.php
- gift-history.php
- stats.php
- images/
- bg-stars.png
- avatar.png
- css/
- style.css
- glow.css
- background.css
- js/
- script.js
- jquery.js
- destiny.js
- snowflake.js
The three folders are images,css and js.
The generator.php requires a $_GET paremeter to know what generator to load.
So far, i've been using the following url:
http://tryhardhusky.com/generator.php?t=destiny
For the other pages, I have the following code in my .htaccess file:
php_value display_errors Off
php_flag magic_quotes 1
php_flag magic_quotes_gpc 1
php_value mbstring.http_input auto
php_value date.timezone America/New_York
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
This pretty much removes the .php extension from the file name, So files that would be:
http://tryhardhusky.com/gift-history.php
becomes:
http://tryhardhusky.com/gift-history
I'm trying to get the following page:
http://tryhardhusky.com/generator.php?t=destiny
to rewrite as
http://tryhardhusky.com/generator/destiny
All my previous attempts have broken the js and css, Returning a 404 error when loading the page (despite the location being correct)
[Error 404 Not Found: http://tryhardhusky.com/js/jquery.js ]
Any clue how I can do this without breaking it?
You can replace your current code by this one in your htaccess
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# rewrite /generator.php?t=XXX to /generator/XXX
RewriteCond %{THE_REQUEST} \s/generator\.php\?t=([^\s&]+)\s [NC]
RewriteRule ^ generator/%1? [R=301,L]
# hide PHP extension for existing files
RewriteCond %{THE_REQUEST} \s/(.+?)\.php(?:\s|\?) [NC]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ %1? [R=301,L]
# internally rewrite /generator/XXX to /generator.php?t=XXX
RewriteRule ^generator/([^/]+)$ generator.php?t=$1 [L]
# internally rewrite to PHP file extension (if existing)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1.php [L]

Remove directory in htaccess with mod_rewrite

I am trying to strip down
http://host.name/html/about.html
to
http://host.name/about.html
But I keep encountering a 404 error with the following in my .htaccess file:
Options +FollowSymLinks
RewriteEngine on
rewritebase /
RewriteRule ^html/(.*) $1 [R,L]
http://htaccess.madewithlove.be/ says its valid, and i think its valid, but there is clearly something I missed.
Can anyone correct me?
Edit:
It also bounces to root when I try to visit /html/
You have it backwards. Since the actual resource is at /html/about.html, you need to internally rewrite to that URI, not from. Once the internal rewrite is in place, you can externally redirect any direct requests to the html directory. So something like:
Options +FollowSymLinks -Multiviews
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /html
RewriteRule ^html/(.*)$ /$1 [L,R=301]
RewriteCond %{DOCUMENT_ROOT}/html%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/html%{REQUEST_URI} -d [OR]
RewriteCond %{DOCUMENT_ROOT}/html%{REQUEST_URI} -s
RewriteRule ^(.*)$ /html/$1 [L]
Or you could replace the last set of conditions/rule to:
RewriteCond %{REQUEST_URI} !^/html/
RewriteRule ^(.*)$ /html/$1 [L]

Rewrite subdomain to subfolder causes loop error or 403

I have a local Apache server set up on my machine, with wildcard DNS in place. I have it set up so that it works like [foldername].loc. So, for instance, a folder under my htdocs folder called MyDomain, would be accessed via mydomain.loc. This code works fine, and the code in my .htaccess in my htdocs is below:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]*\.)?([a-z0-9-]+)\.loc$ [NC]
RewriteCond %3::%{REQUEST_URI} !^(.*?)::/\1/?
RewriteRule (.*) /%3/$1 [PT,QSA]
Now, the above code also passes through subdomains, such as "john.mydomain.loc". Now, I have the following folder structure in the folder MyDomain:
MyDomain
- active
- index.php
- working
- index.php
.htaccess
In the .htaccess of MyDomain is the following code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^live\.mydomain\.loc$ [NC]
RewriteRule ^(.*)$ /active/$1 [L]
What this should do, if I understand correctly, is take http://live.mydomain.loc/ and rewrite it to be http://mydomain.loc/active/. Note that I said rewrite, not redirect.
With the code above, however, I get a message in the Apache error log:
[client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
If I change the .htaccess of MyDomain to read as follows:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^live\.mydomain\.loc$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /active/$1 [L]
When I use this code, it always comes up with a 403 error, saying I don't have permission to view the folder /mydomain/. If I set Options +Indexes, I only see the folder index of /mydomain. So where along the line is the above code failing?
I have also tried the above code with RewriteCond %{REQUEST_URI} !^/active/. This has made no difference in the results.
I have tried this for over two days, and I can't figure it out. I hope the brilliant minds of StackOverflow can help figure this out. :)
Try setting the rewrite base to where the file actually is:
RewriteEngine On
RewriteBase /MyDomain/
RewriteCond %{HTTP_HOST} ^live\.mydomain\.loc$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ active/$1 [L]
And making the /active/ relative: active/
I solved this using the code below:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^live\.mydomain\.loc$ [NC]
RewriteCond %{REQUEST_URI} !^/mydomain/active/
RewriteRule ^(.*)$ active/$1 [L]
The primary fix was RewriteCond %{REQUEST_URI} !^/mydomain/active/. The difference is, the first line I tried, RewriteCond %{REQUEST_URI} !^/active, would match /access/index.php, but not /mydomain/active/index.php.
I hope this helps someone else.

htaccess, Suphp and mod_rewrite issue

I bought a script called fastAmazon. The developer wrote it for traditional server config using mod_rewrite.
My hosting (site5) utilizes SuPHP which I've learned requires that the php config rules be out of htaccess and into the php.ini file. Okay simple enough, commented out php_flag and it finally loaded. The problem is that once I try to go to any other page I get a 500 error.
Something in this config isn't allowing the rewrite of other pages and I CANNOT figure it out!
The dev said it's probably something to do with the [L] line endings but won't help further on a SuPHP config...
#php_flag display_errors Off
RewriteEngine on
RewriteBase /mypages/
RewriteRule ^sitemap.xml$ /sitemap.php?target=google [L]
RewriteRule ^urllist.txt$ /sitemap.php?target=yahoo [L]
RewriteRule ^outgoing/(.*)$ /out.php?url=$1&%{QUERY_STRING} [L]
RewriteRule ^pages/(.*)$ /page.php?page=$1&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?%{QUERY_STRING} [QSA]

Resources