I have had some difficulties with my site after updating my servers to use PHP version 5.4.. I have been through a lot of support tickets and browsed the internet for 2 days.. Now I need to ask directly to the people who actually know about it.
After updating the php version I started to get a 500 error on my pages and it turned out that my rewrite rules in my htaccess file wasn't working anylonger. They did in php version 5.2 but not in 5.4.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
# If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+website\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]
RewriteRule ^([\w.-]+)/?$ website.php?id=$1 [L,QSA]
RewriteRule ^([\w.-]+)/([\w.-]+)/?$ website.php?id=$1&page=$2 [L,QSA]
</IfModule>
Can anybody tell me what I have to do differently? I would really appreciate it.
EDIT:
I got this copy from my livechat with hostgator:
[Thu Jun 26 03:54:07 2014] [error] [client ] malformed header from script. Bad header=<br />: website.php
[Thu Jun 26 03:55:35 2014] [error] [client ] Cannot load the ionCube PHP Loader - it was built with configuration 2.2.0, whereas running engine is API220100525,NTS
[Thu Jun 26 03:55:35 2014] [error] [client ] The Zend Engine API version 220100525 which is installed, is newer.
[Thu Jun 26 03:55:35 2014] [error] [client ] Contact Zend Technologies at http://www.zend.com/ for a later version of Zend Optimizer.
[Thu Jun 26 03:55:35 2014] [error] [client ]
Try adding this line:
zend_extension = /usr/local/ioncube/ioncube_loader_lin_5.4.so
to your php.ini
SOLUTION IS NOW FOUND
I made the wrong assumption to think it was due to my rewrite rule. The problem seemed to be at HostGator. If you host at HostGator, this will be helpful for you. The reason all this started was because HostGator has announced, that the will upgrade the servers to run PHP 5.4 as standard instead of PHP 5.2. What they didn't mention, was the structure of their servers and how individual sites has to manage their individual PHP files.
Well I found out that by changing the name of my php.ini file in the root directory (making it invalid for the server to use), the system located a PHP version specific php.ini file in the main servers directory. This made me realize that the php.ini file in my root directory had to be changed completely, so therefor I created a new php.ini file containing the 5.4 version. The site didn't change, because the files were basically identical, but it made it possible for me to use the EZConfig in cPanel again.
This is what to do:
Change PHP version either in the PHP configuration tab in cPanel, or
by adding AddHandler application/x-httpd-php54 .php to your
.htaccess file.
Open File Manager in cPanel.
Locate your root folder (Home) and find the php.ini file.
If you want to keep your existing php.ini file as a backup, rename it to ex. php_old.ini.
Create a new file named php.ini and insert the content from following link: https://wiki.cac.washington.edu/display/webpub/php.ini+for+PHP+5.4
Good luck with it. Hope this will solve it for somebody as well, so that they don't have to spend 3 days solving it themselves.
Related
actual .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule index.php [L]
target:
All files should point to index.php
also png/xml ect.
call on browser:
http://localhost:8080/test.png
browser message:
enter image description here
log:
[Sun Feb 6 01:23:29 2022] [::1]:57052 Accepted
[Sun Feb 6 01:23:29 2022] [::1]:57052 [404]: GET /test.png - No such file or directory
[Sun Feb 6 01:23:29 2022] [::1]:57052 Closing
my server start to test with:
php -S localhost:8080 -dxdebug.mode=debug -dxdebug.client_host=127.0.0.1 -dxdebug.client_port=9003 -dxdebug.start_with_request=yes
my actual server:
PHP 8.1.1 (cli) (built: Dec 17 2021 22:38:05) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans
with Zend OPcache v8.1.1, Copyright (c), by Zend Technologies
works on macbook ...
have an idea to solve my problem?
PHP 8.1.1 (cli) (built: Dec 17 2021 22:38:05) (NTS)
You are using the built-in PHP webserver. .htaccess (and by extension mod_rewrite) is an Apache config file and is not supported by the PHP webserver.
To implement a front-controller/router using the PHP built-in webserver you need to use PHP, as described in the PHP docs:
https://www.php.net/manual/en/features.commandline.webserver.php
Aside: The mod_rewrite rule is also incorrect and won't work as written:
RewriteRule index.php [L]
You are missing the first argument to the RewriteRule directive, so it will never match the request you are making. It should be something like this:
RewriteRule . index.php [L]
Where . (a single dot) is a regular expression (pattern) that matches at least 1 character (ie. everything except the document root, which is handled by the DirectoryIndex).
Further Reference:
https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewriterule
works on MacBook ...
You must be using Apache, with a different .htaccess file!
I want to encode a long Base64 encoded string within the URL.
Currently long URLs (over 300 chars) that are rewritten under mod-rewrite result in a forbidden(402) error.
If my request URL is 355 characters it results in error, however when I reduce it to 300 it works.
Is there a default value in the server that limits the request line size?
I couldn't find the LimitRequestLine/FieldSize directive anywhere in my server configuration.
Here is my rewrite rule:
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^json/ base64json.php [L]
A URL looks something like this:
http://sub.mydomain.com/json/longrandomnumbers?param=xxx
I wish to extract randomnumbers and param from the rewritten url, but it says forbidden permission denied, inside apache2 error log, it says:
Mon Mar 19 21:03:31.711559 2018] [core:error] [pid 20504] (36)File name too long: [client 167.220.24.128:45071] AH00036: access to /json/eyJldmVudHMiOlt7InNlc3Npb25JZCI6InMxNTAxMjY0OTIzeDYyZjg4MTNlNjkzMWM5eDU4MjQ0MjY2IiwiaW5zdGFudGlhdGlvbiI6IjkxMTMwMDQ3MTQ3OTE1ODgiLCJpbmRleCI6MCwiY2xpZW50VGltZXN0YW1wIjoxNTIwMzg3NTkwLjE2OSwibmFtZSI6ImNyZWF0aXZlTG9hZGVkIiwidmlld2FiaWxpdHkwME1lYXN1cmFibGUiOnRydWUsInZpZXdhYmlsaXR5NTAxTWVhc3VyYWJsZSI6ZmFsc2V9XX0= failed (filesystem path '/var/www/track/json/eyJldmVudHMiOlt7InNlc3Npb25JZCI6InMxNTAxMjY0OTIzeDYyZjg4MTNlNjkzMWM5eDU4MjQ0MjY2IiwiaW5zdGFudGlhdGlvbiI6IjkxMTMwMDQ3MTQ3OTE1ODgiLCJpbmRleCI6MCwiY2xpZW50VGltZXN0YW1wIjoxNTIwMzg3NTkwLjE2OSwibmFtZSI6ImNyZWF0aXZlTG9hZGVkIiwidmlld2FiaWxpdHkwME1lYXN1cmFibGUiOnRydWUsInZpZXdhYmlsaXR5NTAxTWVhc3VyYWJsZSI6ZmFsc2V9XX0=')
and
failed (filesystem path
'/var/www/track/json/eyJldmVudHMiOlt7InNlc3Npb25JZCI6InMxNTAxMjY0OTIzeDYyZjg4MTNlNjkzMWM5eDU4MjQ0MjY2IiwiaW5zdGFudGlhdGlvbiI6IjkxMTMwMDQ3MTQ3OTE1ODgiLCJpbmRleCI6MCwiY2xpZW50VGltZXN0YW1wIjoxNTIwMzg3NTkwLjE2OSwibmFtZSI6ImNyZWF0aXZlTG9hZGVkIiwidmlld2FiaWxpdHkwME1lYXN1cmFibGUiOnRydWUsInZpZXdhYmlsaXR5NTAxTWVhc3VyYWJsZSI6ZmFsc2V9XX0=')
I tried to add RequestLine/FieldSize to apache2.conf, no use, wondering how to by pass the limit for the file system I use and why it's so annoying to check the length somehow before redirect to the correct path which is base64json.php, could I do it as a long parameter instead? It might be caused by ubuntu files system.
I am using Apache2.4.7 on Ubuntu 14.02.
This must be defined before loading any Virtual Host.
Add this in yours apache2.conf, right.
Did you restarted apache daemon after edit?
sudo service apache2 restart
I have this .htaccess file
DirectoryIndex index.php
RewriteEngine on
RewriteRule ^user/([_.0-9a-zA-Z]+)$ show-user.php?user=$1 [L]
which redirects just fine in the browser, but if on the error log on my server I can see hundreds of "File does not exist" errors, do you have any idea why?
Here is an error example from the log:
[Thu Mar 28 02:58:43 2013] [error] [client xxx.xxx.xxx.xxx] File does not exist: /home/folder/public_html/user, referer: domain/user/username0001
And there are hundreds! But everything works fine! What can I do to make these errors not show up?
Fixed, I had to use /show-user.php like this
RewriteRule ^user/([_.0-9a-zA-Z]+)$ /show-user.php?user=$1 [L]
I have the following .htaccess on an Apache/2.4.2-win32 server:
# Turn mod_rewrite on
RewriteEngine On
# Allow direct loading of files in the static directory
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^/?static/(.+)$ - [L]
# Send all other requests to controller
RewriteCond ${REQUEST_URI} !^/?(spf/index\.php)?$
RewriteRule .* spf/index.php [L,QSA]
This works well and does exactly what I want it to. For those of you who can't be bothered working out what it does, it sends all requests through spf/index.php unless they are for a file that exists in the static directory.
The file resides in the virtual host's documentroot.
Every request that falls through this .htaccess generates the following error:
[Wed Aug 01 14:14:16.549835 2012] [core:warn] [pid 7100:tid 1076] AH00111: Config variable ${REQUEST_URI} is not defined
This is not actually causing a problem - every request works as expected - but it's filling up my error log and I don't like it.
According to Google, no-one has ever had this error before. That's as far as I've got with debugging it, I don't really know where to go next.
Anyone got any idea what's going on here?
P.S. I'm aware this might be a question better suited to SF, if the general opinion is that it doesn't belong here I'll move it.
You need to replace the $ with a %:
RewriteCond ${REQUEST_URI} !^/?(spf/index\.php)?$
to
RewriteCond %{REQUEST_URI} !^/?(spf/index\.php)?$
I want to start using mod_rewrite so i can use friendly url's in the future. Im testing all in my localhost dev. environment but, Im not having any luck getting the module to work!
My modules is enabled (apache restarted):
LoadModule rewrite_module modules/mod_rewrite.so
The file named mod_rewrite.so exists under the modules folder in my Apache installation directory
I've created a file named .htaccess under c:/public_html/
For testing purposes, ive created my first rules like so:
RewriteEngine On
# Translate my-product.html to /product.php?id=123
RewriteRule ^my-product\.html$ /product.php?id=123
for testing purposes, the product.php is extremely simple:
<?php
// display product details
echo 'You have selected product #' . $_GET['id'];
?>
When i load http://localhost/my-product.html I get the error:
The requested URL /my-product.html was not found on this server.
When i go see the log, i see:
[Thu Sep 22 02:37:49 2011] [error] [client 127.0.0.1] File does not exist: C:/public_html/my-product.html
It looks like it doesn't recognize the .htaccess rule at all!
I'm not sure what to do next, i feel i've applied all the simpliest rules to get started with mod_rewrite but with no luck!
Help!
Thanks
Marco
Have you changed the Allowoverride property in httpd.conf file to 'All'.
To check whether the mod-rewrite is enabled in your server, load the phpinfo file and search for the mod_rewrite extension.
You should configure the mod_rewrite logging, so you can see what happens. Look up the RewriteLog directive in the manual.
Initially you can set the log level to 9 (for learning). As long as the file stays empty, the .htaccess is ignored, as you already suspected.
You can also just write rubbish into the .htaccess to see if it gets interpreted at all. If it does, you will get a 500 Internal Server Error. If not, you must configure the directory C:/public_html to allow htaccess files. See the Options directive in the manual.