Converting htaccess to nginx for counter - php

I used to have my site hosted on a Apache server and had my htaccess file like this
RewriteEngine On
RewriteBase /
RewriteRule ^debs_public/(.*)\.deb$ counter.php?request=%{REQUEST_FILENAME}
I recently changed to a VPS and set the server up using nginx as per recommendations of it being faster. I've been struggling with the conversion of the htaccess file. I used a converter and got this line.
location /debs_public {
rewrite ^/debs_public/(.*)\.deb$ /counter.php?request=$request_filename;
}
but when I add this to my configuration it results in error 500 internal server error. Any suggestions as to what to change?
Note: What the counter does is count when a deb is downloaded from my Cydia repository. Works fine in Apache but fails in nginx.

Try something like below:
location /debs_public/ {
rewrite ^/debs_public/(.*)\.deb$ counter.php?request=$request_filename; break;
return 403;
}
Hopefully this may work.
Special Quote:
"if these directives are put inside the “/debs_public/” location, the last flag should be replaced by break, or otherwise nginx will make 10 cycles and return the 500 error:"
Refrence: http://nginx.org/en/docs/http/ngx_http_rewrite_module.html

Related

PHP Routing on Apache Server

The following code, in index.php, gives the expected routing behaviour when I run it using the built in php web server:
<?php
$request = $_SERVER['REQUEST_URI'];
switch ($request) {
case '/' :
echo 'This is the Home Page';
break;
case '/about' :
echo ' This is the About Page';
break;
default:
echo 'Resource not Found (404)';
break;
}
The same code uploaded to my Ionos Linux web server running Apache does not work: If I access the root directory from a firefox browser (eg http://mywebsites.org.uk/root-directory) I get Resource not Found (404)in the browser. If I append something to the URL (eg http://mywebsites.org.uk/root-directory/about) the browser just gives some page with advertising on which is what you get when there is nothing corresponding to that path on the server). Same happens if you change 'about' for any other word.
I tried with the following .htaccess file in the root directory along with the index.php file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php [QSA,L]
Now I get the same result with http://mywebsites.org.uk/root-directory. That shows Resource not Found (404) in the browser as before. However, with http://mywebsites.org.uk/root-directory/about or any word substituting 'about' I now get an error message in the browser:
Multiple Choices
The document name you requested (/index.php) could not be found on this server. However, we found documents with names similar to the one you requested.
Available documents:
/index.html (common basename)
When I click on index.html (which is hyperlinked) I find that it is in the directory above the root-directory with the index.php file in it. Ie it is in the mywebsites.org.uk directory. Obviously it is not what I am after.
I also tried replacing the content of the .htaccess file with FallbackResource /index.php. The result was the same as when I had no .htaccess file at all which I described earlier.
I am finding it very difficult to understand my Ionos web server. I do not know if I can change configuration files for Apache or not and I have little understanding of .htaccess files. I have thought of changing to AWS over this issue as the documentation there seems more thorough. However I would prefer not to change if I can sort this issue out. Basically I want to be able to build a PHP router on my Ionos server which runs Apache.,
You are correct that the built-in PHP web server enables you to use a routing script. However, in environments such as your hosting on Ionos, this function is generally performed by whatever web server is running.
Unfortunately, I'm having trouble finding which web server Ionos offers by scanning their web site. Are you certain that they are running Apache and that they have mod_rewrite and local .htaccess overrides enabled? Any of these could explain why you're having issues there.
From your description of your issues, it also sounds like your web site may not have its document root path configured correctly, or that it is not set up to use index.php as a directory index file (e.g. via the DirectoryIndex Apache configuration setting).
The best I can suggest is contacting Ionos techical support or seeking out any technical documentation they offer to customers. I can't even tell if or what configurations they may allow you to override.

Error 404 while opening site, httpd.conf?

I have a php application that I needed to open on a local web server. I'm running Windows 7 on my VM. Have installed php 7.3.6, mysql, apache 2.4.
After some configuration trying to open my "application" with "localhost/application".
Getting "Internal error 500".
In Apache logs can see "C:/WebData/application/.htaccess: Invalid command 'order', perhaps misspelled or defined by a module not included in the server configuration"
In .htaccess I have:
order deny,allow
RewriteEngine On
RewriteBase /
RewriteRule .* index.php?url=$0 [QSA,L]
Change first line into "Require all granted"
Trying to open "localhost/application"
Getting the error "404 URL /index.php" not found
Trying to open "localhost/application/index.php"
Forwarding to "localhost/ru/main"
Getting another error "404 URL .." not found
Also after each request I see that htaccess is changing back into its initial state with "order deny,allow".
Is there something wrong with httpd.conf?
You probably don't run mod_access_compat, which means Order is not available, as it's deprecated in Apache 2.4 (see https://httpd.apache.org/docs/2.4/howto/access.html)
Now, the reason why your .htaccess files get overwritten probably lies in the PHP code you're running. Some applications try to auto-configure themselves and will write their own .htaccess file to make sure they run properly.
The fact this particular app tries to write deprecated commands without checking if the version of Apache you are running is capable of handling them is concerning and probably means it's outdated.
Do a global search on the application files and look for that Order deny, allow rule, I'm pretty sure you'll find the culprit.
If you can run a newer version of that code, do so, and if not, and if patching it manually is an option, change it to Require all granted

http://example.com/portal/p/Logon/ not working after migration (Apache, php)

I have migrated a dynamic website (php, mysql) to a new host on a shared server plan.
The site is fully dynamic and has no fixed paths as such apart from the single entry point file "portal.php". The site exists as path-info to portal.php and is created from templates in a mysql database. There is no /portal directory, for example.
The homepage loads fine, but not subpages.The pathinfo is returned correctly, but the webserver is not translating it I guess:
http://example.com/portal/p/Logon = Fails with 404 error
http://example.com/portal.php/p/Logon = Works!
I have limited control over the apache server as the client has a basic, shared server plan.
I tried various options in a .htaccess file at the root of the website directory, but the best I could do was get an internal 500 error. At least I know the .htaccess is being read.
I'm hoping I can resolve this, otherwise I will have to migrate the site to a dedicated server instead.
Ok I found a solution. I see now why my initial post lacked information :)
I read this guide:
https://httpd.apache.org/docs/current/content-negotiation.html
And after trial and error, the following worked with a .htaccess file placed at root (I modified a html5boilerplate .htaccess file):
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteRule ^portal/(.*) /portal.php/$1
RewriteRule ^portal$ /portal.php

Why does this Rewrite rule throws a 500 inside .htaccess file?

on a server with PHP and mod_rewrite I have the following .htaccess in the document root:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .(rewriteme)$ rewrite.php [L]
</IfModule>
When I make a request to http://theserver.com/arewriteme, I get a 500 internal server error.
But on my local system, the rule above works great and the script rewrite.php is executed (it simply echoes It works!) when I request http://localhost/arewriteme:
<?php echo "It works!"; ?>
Why do I get a 500 error on the remote server though? I don't have access to the global Apache configuration, but I am sure the module gets loaded as `phpinfo() shows:
I looked at different questions here on SO, but basically all say that it the error is due a syntax error within .htaccess (which is not my case because the rule works on localhost).
So, maybe, there's something in the global configuration of Apache? Maybe the creation of .htaccess is somehow denied? Could it be possible?
Thanks for the attention.
EDIT: I was able to contact the hosting provider and they told me that they disabled .htaccess throught the whole htdocs directory. How did they do that so that the server thrown a 500 Internal Server Error? AllowOverride None inside the main Apache won't do the job because in this case Apache would simply ignore the rules inside the .htaccess but won't throw any error...

XMAPP - PHP - Error 400

So, this question has probably been answered before but i have changed ports in my conf files which most other posts has not. I'm suspecting this is why it won't work.
So, first i had a problem where skype was using the ports xmapp used, so i changed them to : 8080 and 4433. I also changed server name to : localhost:8080 and www.example.com:4433
When i try to go to localhost:4433 using google chrome i get :
Error 400
"Bad Request!, Your browser (or proxy) sent a request that this server could not understand."
And when i try with just localhost i get a white page.
And when i try t go to phpadmin "localhost/phpmyadmin"
it displays a white page.
Both mySql and Apache servers are running without any errors.
Any idea why and how to fix this problem? I've spent 15 hours now fixing 3 different errors.
actually you have change this port at two places in httpd.conf file,i.e
1) Listen 80
2) ServerName localhost:80
at the above places the port value should be 4433, as per your changes
Old question, but I had this error start suddenly to my XAMPP instance on WIndows 7.
It started when I was doing a cleanup and removed a folder that was referenced as a redirect in the .htaccess file.
e.g.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
If the folder public is removed/renamed, this error will start to occur, even with the simplest of PHP or HTML files being requested.
I fixed by removing the .htaccess - when I need it again I'll add it back in with the right paths.

Categories