Convert htaccess rules routing paths to index.php to nginx - apache

I'm new to nginx, but I'm trying to convert
# Disallows file browsing
Options -Indexes
# Custom Error Pages
ErrorDocument 403 /error-docs/403.php
ErrorDocument 404 /error-docs/404.php
ErrorDocument 500 /error-docs/500.php
# Turn on the Apache Rewrite Engine
RewriteEngine On
#Conditional to see if it is a real file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# If not then pass the query string to index.php and stop any further rules
RewriteRule (.*) index.php/$1 [PT,L]
to nginx syntax. I've tried the suggestion at Routing requests through index.php with nginx but it doesn't do quite what I need it to do. I've also tried the auto converters http://winginx.com/en/htaccess and http://www.anilcetin.com/ but the rules they output don't work for me either. Any help is appreciated.

The issue I had was actually related to my PHP and MySQL code.
location / {
try_files $uri $uri/ /index.php$args;
}
works fine. Thanks for the link.

Related

vue-router url paths are giving a 404 in production with nodejs

I am attempting to deploy a multipage vue3 frontend to an application. It works fine in development mode, but in production, when I attempt to navigate to a url via the search bar -- e.g. https://mywebsite.com/customers, I get a 404.
I am able to fix this by redirecting to the homepage using the suggestion on vue-router's documentation, but then it just goes to the homepage rather than showing the actual page I would like to visit. Is there some way around this that I am missing? An additional step or does this suggest I am misconfiguring this somehow?
I solved this by setting up the server. You need to understand what server you have installed. Go to config update and restart the server.
Here are the Server Configurations
Apache
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
nginx
location / {
try_files $uri $uri/ /index.html;
}

File Manager of CKEditor WolfCMS not working with Nginx

I migrated a WolfCMS from Apache to Nginx. Everything is working fine except for the CKEditor File Manager plugin. When opening the browser server box of CKEditor I am seeing No input file specified. All other friendly URLs, rewrites are working without any issues. So I assume the issue is related to a wrong Nginx configuration.
These are the Apache rewrites:
RewriteEngine On
# Set next line to your Wolf CMS root - if not in subdir, then just /
#RewriteBase /wolfcms/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
# Main URL rewriting.
RewriteRule ^(.*)$ index.php?WOLFPAGE=$1 [L,QSA]
For Nginx the docs just state:
#Put the following code in your server block:
try_files $uri $uri/ /index.php?WOLFPAGE=$uri&$args;
And that is what I did. The file manager URL that is not working in Nginx is:
/wolf_ckeditor/filemanager/index.php?type=Images&CKEditor=part_0_content&CKEditorFuncNum=1&langCode=de
=> Leading to No input file specified.
Any suggestions on how I could modify my Nginx config to get this working again?

Let Apache check for errors before RewriteRule in .htaccess

Is it possible for Apache to process errors before any RewriteRule?
I have the following:
RewriteEngine on
RewriteRule ^(.*).(htm|html)$ /cgi-bin/processor.py?file=$1.$2 [L]
So any .htm(l) files are sent to a python script. However, before that happens, I'd like any errors, such as a 404 to be checked for. That way, if I go to fakeFile.html I get my ErrorDocument 404 page, instead of having to handle that in my script.
Is that possible?
Thanks.
You can use:
# handle 404 error
ErrorDocument 404 /404.html
RewriteEngine on
# rewrite only if .html file exists
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+?\.html?)$ /cgi-bin/processor.py?file=$1 [L,QSA,NC]

'nginx rewrite' to '.htacces rewrite'

Im very bad in regexps, but in server-configs im the worst.
So any help ll be usefull.
have such in nginx-config
location / {
rewrite ^(.*[^/])$ $1/ permanent;
try_files $uri $uri/ /index.php?$args;
}
need EQUAL thing for .htacces.
Ty.
They should prove very similar.
<IfModule mod_rewrite.c>
RewriteEngine On
# Your web directory root
RewriteBase /
#Make sure it's not a specific file or directory that they're trying to reach
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*[^/])$ index.php?args=$1 [NC, L]
</IfModule>
This will:
Mark RewriteEngine on for the folder the .htaccess is in (if you've got the module enabled);
Specify conditions to avoid redirection if the file is a directory or a file on the server; And
Redirect your Regex to index.php?args={everything caught by the regex}
The [NC, L] flags tell the rule to be not case sensitive and tell Apache this is the last redirection rule, respectively.
I have to admit, I'm not sure what your Regex is testing for though. Would you mind explaining the URL scheme you want to put in place? I should be able to help you formulate the Regex properly.

Apache config to direct all requests to the same page

I am creating a custom web server that is designed to serve a single page, regardless of the request URL:
- www.example.com/
- www.example.com/spam/eggs/spam/?ID=eggs
- foo.example.com/
- ...
I am using a wildcard DNS entry to handle the subdomains, but I'm wondering about the best way to handle the page requests.
My first thought was simply to have no pages on the site and create a custom 404 page which was the page I wanted to serve, but I thought that losing an error page might have problems in the future, not to mention sending a 404 error to the client might have effects I am not aware of. Should I be using mod-rewrite instead?
How would you do this? 404, mod_rewrite, or?
I'll use this as an answer
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>