So, when I put in my .htaccess file which contains the following:
# Use PHP5 php.ini as default
AddHandler application/x-httpd-php5 .php
AcceptPathInfo On
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [L,QSA]
The server tries to download the PHP file instead of executing it. When I remove the .htaccess file, everything works fine and the PHP files execute.
I'd remove the AddHandler directive. Leave this to the server config.
Everything else looks fine.
It could very well be the AddHandler application/x-httpd-php5 .php
Are you including this because your server is setup to not run PHP5 by default?
I found the issue in the end, I had the entire thing set up correctly. There is a bug in PHP5, that had happened due to some of the discontinuing support of $_SERVER['ORIG_PATH_INFO']. This is not true in windows servers, however in PHP 5.4.2 (Linux Distro) ORIG_PATH_INFO is not supported any more, only PATH_INFO. A report has been made about this. But all is up and running. Thanks for your guys' help and responses.
Related
How am I able to hide a .php extension in an URL address, so that this address:
http://www.thesite.com/somefile.php
would look like:
http://www.thesite.com/somefile
without the use of the .htaccess file. The reason for that being because I have many directories and would want to hide the extension on all those files in every directory. I have tried to set expose_php to off, and this still fails with error 404.
I am using PHP 5.3.10 and Apache server.
Although you specifically said no, using the .htaccess file would remove the .php extension from all PHP files in all subdirectories in a site. I think that is what you are going for.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>
Putting that into the .htaccess file will remove all the .php file extensions. Or you could put it directly into the webserver's configuration files.
You can achieve this with URL rewriting. If you don't want to use .htaccess, you can write the rule in your host configuration file.
I made a website for an sports club in the area. I always ran it on my own server (apache2) when building and testing it and use .htaccess to make some rewrites. Now the website is going live on their server, only problem is they're running on a cgi/fastcgi server...
I'm not that experienced with that kind of IT terms and modifications, so i hope you'll can help me or give me some advice. What is the best way to make the .htaccess work (and the whole website, which also includes php code)? At the moment the website gives an "(IIS 8.5 Detailed Error) HTTP Error 403.14 - Forbidden" error. Also their running PHP7...
Hope somebody can help me!! Thanks!!
.htaccess
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# redirect while under construction
RewriteCond %{REMOTE_ADDR} !^my\.ip\.addr\.ess$
RewriteCond %{REQUEST_URI} !construction\.html
RewriteRule ^(.*)$ /construction.html [R=302,L]
# remove .html extensions from the URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
# convert html to php without changing the extension
AddType application/x-httpd-php .htm .html
ErrorDocument 404 /errors/404.html
This has nothing to do with CGI or FastCGI.
.htaccess is an Apache HTTP specific means of configuring your HTTP server.
If you want to configure Microsoft Internet Information Server then you have to use the IIS configuration methods, not Apache configuration methods.
(You are trying to configure three completely different things in your Apache configuration file, so I'm not going to look up detailed instructions for the IIS equivalents of all of them).
For simple web application, how can we use ".main" as the URI extention in place of .php or .html ? How can we change example.com/test.php to exmple.com/test.main, without actually renaming the file.
Thanks
You can use the apache extension mod_rewrite. Here's a sample of what you can do.
RewriteEngine On
RewriteRule ^(.*)\.main$ $1.php
This will take any request with the extension .main and actually serve the file with the same name but extension .php.
ModRewrite is a great solution for such things, however, to permanently have a different extension for you PHP files while they are still recognised and executed as PHP, use Apache's SetHandler module.
Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.main$ $1.php [R=301,L]
Also please see this Tutorial: An In Depth Guide to mod_rewrite for Apache http://net.tutsplus.com/tutorials/other/a-deeper-look-at-mod_rewrite-for-apache/
In IIS, you would use the Manage Handlers script to assign the PHP FastCGI executable to .main file extensions.
How am I able to hide a .php extension in an URL address, so that this address:
http://www.thesite.com/somefile.php
would look like:
http://www.thesite.com/somefile
without the use of the .htaccess file. The reason for that being because I have many directories and would want to hide the extension on all those files in every directory. I have tried to set expose_php to off, and this still fails with error 404.
I am using PHP 5.3.10 and Apache server.
Although you specifically said no, using the .htaccess file would remove the .php extension from all PHP files in all subdirectories in a site. I think that is what you are going for.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>
Putting that into the .htaccess file will remove all the .php file extensions. Or you could put it directly into the webserver's configuration files.
You can achieve this with URL rewriting. If you don't want to use .htaccess, you can write the rule in your host configuration file.
What handles the disabling of the extension? Is it APACHE or the PHP install? How would one go about configuring the web server where the .php extension is not required? Is there an option that would make both www.example.com/page.php and www.example.com/page work as the URL?
It's URL rewriting through Apache:
http://www.addedbytes.com/apache/url-rewriting-for-beginners/
Apache also has a setting called MultiViews that will serve domain.com/index.* as domain.com/index, domain.com/example.* as domain.com/example, etc.
I've occasionally run into issues where MultiViews beats out mod_rewrite rules, so I tend to turn it off.
Check out some articles from A List Apart on this topic: You use Apache (in your case) to setup ReWriteRule's and then you have PHP parse the url to fetch the correct information. (again, in your case. You can do this with many languages and http servers)
http://www.alistapart.com/articles/succeed/
http://www.alistapart.com/articles/urls/
brianreavis is correct. Here's an example for your .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
I just throw it all at PHP and parse it however I want in there:
.htaccess
RewriteEngine On
RewriteRule !\.(js|ico|gif|jpg|png|css)$ #frontend.php
I use this in my .htaccess
<Files ~ "^[^.]+$">
ForceType application/x-httpd-php5
</Files>
That way I can remove all extensions (.php) from my files, and it will still work.
I use $_SERVER['PATH_INFO'] to retrieve the remainder of the path as parameters. E.g. /page/param1/param2 where page is an actual php file.